php - 将使用支票付款方式制作的订单状态更改为 "processing"状态

标签 php wordpress woocommerce orders payment-method

我需要通过检查进入“正在处理”状态而不是“暂停”状态来使 WooCommerce 推送付款。我尝试了下面的代码片段,但它似乎没有效果。

这是我的代码:

add_filter( 'woocommerce_payment_complete_order_status', 'sf_wc_autocomplete_paid_orders' );

function sf_wc_autocomplete_paid_orders( $order_status, $order_id ) {

$order = wc_get_order( $order_id );

if ($order->status == 'on-hold') {
    return 'processing';
}

return $order_status;
}

我怎样才能做到这一点?

谢谢。

最佳答案

这是您在 woocommerce_thankyou 钩子(Hook)中看到的函数:

add_action( 'woocommerce_thankyou', 'cheque_payment_method_order_status_to_processing', 10, 1 );
function cheque_payment_method_order_status_to_processing( $order_id ) {
    if ( ! $order_id )
        return;

    $order = wc_get_order( $order_id );

    // Updating order status to processing for orders delivered with Cheque payment methods.
    if (  get_post_meta($order->id, '_payment_method', true) == 'cheque' )
        $order->update_status( 'processing' );
}

此代码位于您的事件子主题(或主题)的 function.php 文件中或任何插件文件中。

这已经过测试并且有效。


相关主题:WooCommerce: Auto complete paid Orders (depending on Payment methods)

关于php - 将使用支票付款方式制作的订单状态更改为 "processing"状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39920555/

相关文章:

php - 如何隐藏 system() 输出

php - 如何在提交时下载在 PHP 中同时创建的文件?

wordpress - wordpress中的主题目录路径

php - 如何从 Woocommerce 中的“我的帐户”中删除 "Paypal payments"选项卡

php - Woocommerce - 在用户注销时清除购物车

php - 10天后删除处理订单

php - 使用 xmlns :xlink attribute in a node 创建 XML

php - 垂直显示月份名称而不是水平显示

php - WooCommerce 添加到购物车后停止重定向

html - 内置在 Wordpress 上的列简码 - 漂亮的边框解决方案