2

I would like to disable the "Place order" button when a specific shipping method is selected, a bit like in "Disable "Place order" button for specific shipping zone in WooCommerce" answer to my previous question, but for a specific Shipping Method instead of a Shipping Zone.

The name of the related shipping method is "LATAM".

Any help is appreciated.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399

1 Answers1

4

First you need to inspect the shipping methods radio buttons, to find out the shipping method ID corresponding value to "LATAM"…

enter image description here

To make it work for a specific shipping method ID you will use the following:

add_filter('woocommerce_order_button_html', 'disable_place_order_button_html' );
function disable_place_order_button_html( $button ) {
    // HERE define your targeted shipping method id
    $targeted_shipping_method = "flat_rate:14";

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

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

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • thanks, Loic, that works perfectly! Now I am able to force customers from specific reasons to request a quote (with a quote plugin). Thank you very much! – Christian Graf Aug 02 '19 at 13:25
  • @LoicTheAztec can you help me here in my question https://stackoverflow.com/questions/57327907/woocommerce-set-currency-based-on-the-session-variable – NewUser Aug 02 '19 at 13:55