【发布时间】:2022-12-15 07:11:16
【问题描述】:
我们目前使用 Autonami 插件来完成此操作,但我觉得它已经过时了,我想删除该插件并通过函数文件来完成。
当 WC 订单设置为 Status“Processing”(不确定是否为大写)时,检查自定义字段“Schedule”的值是否包含单词“Every”。如果是,将状态更改为“我的自定义状态”
那会很容易完成吗?
谢谢!
/J
我不知道从哪里开始。
【问题讨论】:
-
我使用 ChatGPT AI 来生成代码!惊人! ibb.co/HCgt0RJ
add_action( 'woocommerce_new_order', 'change_order_status_to_done' ); function change_order_status_to_done( $order_id ) { // Get the custom field value $custom_field = get_post_meta( $order_id, 'your_custom_field_name', true ); // Check if the custom field contains the word "Every" if ( strpos( $custom_field, 'Every' ) !== false ) { // Set the order status to "Done" $order = wc_get_order( $order_id ); $order->update_status( 'done' ); } }
标签: woocommerce