有条件地从 WooCommerce 我的帐户订单中删除取消按钮

Jei*_*eil 2 php wordpress payment-gateway orders woocommerce

当“付款方式标题”为“Npay”时,我想确保取消按钮在 my-account> my-order 中不可见。

“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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Loi*_*tec 5

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

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;
}
Run Code Online (Sandbox Code Playgroud)

但是要根据付款标题从我的帐户订单中删除取消按钮,您将使用如下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;
}
Run Code Online (Sandbox Code Playgroud)

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

主变量参数$actions需要在IF语句外的最后返回