首页 > 解决方案 > 有条件地从 WooCommerce 我的帐户订单中删除取消按钮

问题描述

当“付款方式标题”为“Npay”时,我想确保取消按钮在我的帐户>我的订单中不可见。

“Npay”是一个外部支付网关,不适用于商业。因此,付款取消只能在外部进行。

add_filter('woocommerce_my_account_my_orders_actions', 'remove_my_cancel_button', 10, 2);
function remove_my_cancel_button($actions, $order){
    if ( $payment_method->has_title( 'Npay' ) ) {
        unset($actions['cancel']);
        return $actions;
    }
}

标签: phpwordpresswoocommercepayment-gatewayorders

解决方案


要从我的帐户订单中删除取消按钮,我们使用以下内容:

add_filter('woocommerce_my_account_my_orders_actions', 'remove_myaccount_orders_cancel_button', 10, 2);
function remove_myaccount_orders_cancel_button( $actions, $order ){
    unset($actions['cancel']);

    return $actions;
}

但是要根据付款标题从 My account Orders 中删除取消按钮,您将使用如下WC_Order方法get_payment_method_title()

add_filter('woocommerce_my_account_my_orders_actions', 'remove_myaccount_orders_cancel_button', 10, 2);
function remove_myaccount_orders_cancel_button( $actions, $order ){
    if ( $order->get_payment_method_title() === 'Npay' ) {
        unset($actions['cancel']);
    }
    return $actions;
}

代码在您的活动子主题(或活动主题)的functions.php 文件中。测试和工作。

主变量参数$actions需要在IF语句的末尾返回


推荐阅读