WooCommerce,X天后自动取消处理订单状态

时间:2020-08-14 作者:Morten Hansen

正在尝试在函数中使用此代码。php,但不工作。。知道怎么了吗?

// To change the amount of days just change \'-7 days\' to your liking
function get_unpaid_submitted() {        
            global $wpdb;

            $unpaid_submitted = $wpdb->get_col( $wpdb->prepare( "
                    SELECT posts.ID
                    FROM {$wpdb->posts} AS posts
                    WHERE posts.post_status = \'wc-processing\'
                    AND posts.post_date < %s
            ", date( \'Y-m-d H:i:s\', strtotime(\'-14 days\') ) ) );

            return $unpaid_submitted;
    }

    // This excludes check payment type.
    function wc_cancel_unpaid_submitted() {        
            $unpaid_submit = get_unpaid_submitted();

            if ( $unpaid_submit ) {                
                    foreach ( $unpaid_submit as $unpaid_order ) {                        
                            $order = wc_get_order( $unpaid_order );
                            $cancel_order = True;

                            foreach  ( $order->get_items() as $item_key => $item_values) {                                
                                    $manage_stock = get_post_meta( $item_values[\'variation_id\'], \'_manage_stock\', true );
                                    if ( $manage_stock == "no" ) {                                        
                                            $payment_method = $order->get_payment_method();                                        
                                            if ( $payment_method == "cheque" ) {
                                                    $cancel_order = False;
                                            }
                                    }                                
                            }
                            if ( $cancel_order == True ) {
                                    $order -> update_status( \'cancelled\', __( \'Pagamento não identificado e cancelado.\', \'woocommerce\') );
                            }
                    }
            }        
    }
    add_action( \'woocommerce_cancel_unpaid_submitted\', \'wc_cancel_unpaid_submitted\' );
    /* End of code. */

1 个回复
SO网友:Sam

您需要知道,您可以直接使用函数中的函数来完成。php文件或插件,但这不是最好的解决方案。对我来说,最好的解决方案是将cron作业与您的操作关联起来,因为您希望每小时/天/周/月检查订单的付款状态。您不希望每次需要检查此状态时都在网站上连接自己以进行功能工作。

(顺便说一句,很抱歉我的英语不好)

对于您的问题,我在此处查看您的代码:https://wordpress.org/support/topic/expiring-on-hold-cheque-orders-after-x-days/#post-10000589

我认为,只有将操作添加到cron作业中,此解决方案才会起作用。

相关推荐