Remove cancel button from WooCommerce My account Orders conditionally

不羁的心 提交于 2020-08-19 05:26:09

问题


I want to make sure the cancel button is not visible in my-account> my-order when 'Payment Method Title' is 'Npay'.

The 'Npay' is an external payment gateway and does not work with the commerce. Therefore, payment cancellation must be done externally only.

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;
    }
}

回答1:


To remove the cancel button from My account Orders, we use the following:

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;
}

But to remove the cancel button from My account Orders based on the payment title, you will use the WC_Order method get_payment_method_title() like:

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;
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

The main variable argument $actions need to be returned at the end outside the IF statement



来源:https://stackoverflow.com/questions/56178408/remove-cancel-button-from-woocommerce-my-account-orders-conditionally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!