Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
00 Days
00 Hours
00 Minutes
00 Seconds

How to Disable ‘Place Order’ Button for Specific Shipping Zone in WooCommerce?

The code snippet will help you to disable the “Place Order” button in WooCommerce for a specific shipping zone.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
add_filter('woocommerce_order_button_html', 'ts_disable_place_order_button_html' );
function ts_disable_place_order_button_html( $button ) {
// HERE define your targeted shipping zone
$targeted_zone_name = "India";
// Get the chosen shipping method (if it exist)
$chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_method = reset($chosen_shipping_methods);
$chosen_shipping_method = explode(':', $chosen_shipping_method );
$chosen_shipping_zone = WC_Shipping_Zones::get_zone_by( 'instance_id', end($chosen_shipping_method) );
// If the targeted shipping zone is found, disable the button
if( $targeted_zone_name == $chosen_shipping_zone->get_zone_name() ) {
$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;
}
add_filter('woocommerce_order_button_html', 'ts_disable_place_order_button_html' ); function ts_disable_place_order_button_html( $button ) { // HERE define your targeted shipping zone $targeted_zone_name = "India"; // Get the chosen shipping method (if it exist) $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); $chosen_shipping_method = reset($chosen_shipping_methods); $chosen_shipping_method = explode(':', $chosen_shipping_method ); $chosen_shipping_zone = WC_Shipping_Zones::get_zone_by( 'instance_id', end($chosen_shipping_method) ); // If the targeted shipping zone is found, disable the button if( $targeted_zone_name == $chosen_shipping_zone->get_zone_name() ) { $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; }
add_filter('woocommerce_order_button_html', 'ts_disable_place_order_button_html' );
function ts_disable_place_order_button_html( $button ) {
    // HERE define your targeted shipping zone
    $targeted_zone_name = "India";

    // Get the chosen shipping method (if it exist)
    $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping_method  = reset($chosen_shipping_methods);
    $chosen_shipping_method  = explode(':', $chosen_shipping_method );
    $chosen_shipping_zone    = WC_Shipping_Zones::get_zone_by( 'instance_id', end($chosen_shipping_method) );

    // If the targeted shipping zone is found, disable the button
    if( $targeted_zone_name == $chosen_shipping_zone->get_zone_name() ) {
        $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;
}

Output

In the below output, when the customer chooses the Zone ‘India’ the place order button gets disabled. If any other zone is selected the place order button will be clickable, thus allowing customers to proceed on placing the order.


How to Disable 'Place Order' Button for Specific Shipping Zone in WooCommerce?

Based on specific requirements you can disable or remove such buttons from your store.Similarly, you can also remove proceed to checkout button from cart page in WooCommerce.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of


0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.