skip to Main Content

My woocommerce shop is UK based, selling bulky items to both the UK market and internationally using FedEx.

I use FedEx for international shipping but sometimes an address cannot be shipped to and the customer gets the ‘no shipping available’ message. However, as far as I can tell, Woocommerce STILL allows the customer to place the order in these situations resulting in an order that cannot be fulfilled. Is there a simple setting somewhere that I am missing that says if no shipping is available, don’t let the order be placed?

I did find this resource – https://www.bolderelements.net/support/knowledgebase/removing-checkout-button-shipping-not-available/ but that only removes the ability to get to the checkout page.

It seems like there should be a setting for something this basic?

2

Answers


  1. Chosen as BEST ANSWER

    I ended up solving this by not hiding the button, but by forcing an error if there is no shipping. I'm using the woocommerce_checkout_process action for this:

    function is_valid_shipping() {
        $selected_shipping = WC()->session->get('chosen_shipping_methods');
        if(in_array(false, $selected_shipping)){
            wc_add_notice( __( 'Your Shipping is not valid.' ), 'error' );
        }
    }
    add_action( 'woocommerce_checkout_process', 'is_valid_shipping' );
    

    Hope this helps someone else!


  2. This code wors for me. It hides the "checkout" button on checkout page if there are no available shipping methods. Goes into your child theme’s functions.php.

    //Hide checkout button if no shipping is available
    add_filter('woocommerce_order_button_html', 'hide_checkout_button__no_shipping_html' );
    function hide_checkout_button__no_shipping_html( $button ) {
    
        $packages = WC()->shipping->get_packages();
        foreach( $packages as $key => $pkg ) {
            $package_counts[ $key ] = count( $pkg[ 'rates' ] );
        }
    
        if( in_array( 0, $package_counts ) ) { //no available shipping method
            $button = '';
        }
        return $button;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search