问题
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 theIF
statement
来源:https://stackoverflow.com/questions/56178408/remove-cancel-button-from-woocommerce-my-account-orders-conditionally