I would like to remove the "Place order" button when a specific shipping method is selected, using the code of the excellent LoicTheAztec "Disable “Place order” button for specific shipping method in WooCommerce" but excluding the order-pay endpoint.
I tried the following solution but it doesn't work, the Place Order button also disappears on the order-pay endpoint.
add_filter('woocommerce_order_button_html', 'disable_place_order_button_html' );
function disable_place_order_button_html( $button ) {
if ( is_checkout() && ! is_wc_endpoint_url( 'order-pay' ) ) {
// HERE define your targeted shipping method id
$targeted_shipping_method = "table_rate:3";
// Get the chosen shipping method (if it exist)
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
// If the targeted shipping method is selected, we disable the button
if( in_array( $targeted_shipping_method, $chosen_shipping_methods ) ) {
$style = 'style="background:Silver !important; color:white !important; cursor: not-allowed !important; text-align:center;"';
$text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
$button = '<a class="button" '.$style.'>' . $text . '</a>';
}
}
return $button;
}
Any help is appreciated.
I tested your code and it works for me. The problem is not related to this code.
The hook for the Pay for order button is woocommerce_pay_order_button_html
and not woocommerce_order_button_html
. You find it in the template: /woocommerce/checkout/form-pay.php
You could remove the
! is_wc_endpoint_url( 'order-pay' )
check because it will never run on that page.
You could check a few things:
woocommerce_pay_order_button_html
hook.