wordpress 如果条件为真[关闭],则阻止订单进入处理状态

lxkprmvk  于 5个月前  发布在  WordPress
关注(0)|答案(1)|浏览(72)

**已关闭。**此问题不符合Stack Overflow guidelines。目前不接受回答。

这个问题似乎与help center中定义的范围内的编程无关。
22天前关闭
Improve this question
我尝试了许多方案和挂钩,并在年底甚至在子模板文件感谢页面
因此,如果订单没有失败并且全局变量== true切换到pending:

<?php if ($order->has_status('failed')) : ?>

//code

<?php else : ?>

<?php if ($GLOBALS['variable'] == true) : ?>

    <?php $order->update_status('pending'); ?>

<?php endif; ?>

字符串
状态正在更改,但问题是它正在从处理状态变为挂起状态。如果condition($GLOBALS <$'variable'])为true,如何防止进入处理状态?

8i9zcol2

8i9zcol21#

您可以尝试以下的货到付款(COD)付款方式,将代码中的'my_variable'替换为正确的slug:

add_filter( 'woocommerce_cod_process_payment_order_status', 'conditionally_change_cod_order_status_to_pending', 10, 2 );
function conditionally_change_cod_order_status_to_pending( $status, $order ) {
    $global_var = $GLOBALS; 

    if ( isset($global_var['my_variable']) && $global_var['my_variable'] ) {
        return 'pending';
    }
    return $status;
}

字符串
代码放在你的子主题的functions.php文件中(或者插件中)。它应该可以工作。

相关问题