• Resolved Gem @White Rabit

    (@anna_tianna)


    Hi All,

    I hope someone can help me iv been trying to solve this now for 2 weeks.

    I am building a site that has some restrictions on specific products. These products can only be shipped to specific UK postcodes. I need a message to show in the shopping cart if the product can not be shipped.

    I have set up 2 shipping classes. Let’s call them Shipping class A and B.

    Products in shipping class A can be shipped anywhere in the UK
    Products in Shipping class B can only be shipped to specific postcodes.

    I need a message to be displayed in the shopping cart saying this product can not be shipped to your area preferably in the product info box so it can be removed.

    Please help

Viewing 3 replies - 1 through 3 (of 3 total)
  • I had to do a similar thing but based it on postcodes (Guernsey and Jersey) and used this:

    
    // Change the WooCommerce 'No shipping methods available' message
    
    add_filter( 'woocommerce_cart_no_shipping_available_html', 'mh_no_shipping_message', 10, 2 );
    add_filter( 'woocommerce_no_shipping_available_html', 'mh_no_shipping_message', 10, 2 );
    
    function mh_no_shipping_message() {
    
    	$message = '<img class="alignleft" src="/images/too-heavy.jpg" <br>Your basket is either too heavy or shipping is not available to this destination. Please <a href="contact-us" target="_blank">contact us </a> to discuss delivery options. Thank you.';
    	$message2 = 'Unfortunatly we are unable to ship to the Channel Islands due to restrictions on paint being transported by air. Please specify a UK mainland delivery address or <a href="contact-us" target="_blank">contact us </a> to discuss delivery options. Thank you.';
    	$pcode = WC()->customer->get_shipping_postcode();
         if (mb_substr($pcode, 0, 2) == 'GY' || mb_substr($pcode, 0, 2) == 'JE') {        
    		return '<p>' . __( $message2, 'woocommerce' ) . '</p>';
        }else{
    		return '<p>' . __( $message, 'woocommerce' ) . '</p>';
        }           	
    }
    
    Thread Starter Gem @White Rabit

    (@anna_tianna)

    Hi @seank123

    Thank you so much for this. It is a step in the correct direction. I will try and tweak it to do as I need.

    Thanks

    Gem

    Thread Starter Gem @White Rabit

    (@anna_tianna)

    Hi @seank123

    How can I change it to do this?

    If no shipping method available show message 1
    If another product from another shipping class is added + a gas bottle that can’t be shipped show message 2. Could this be done via shipping classes for example
    If shipping class Gas Bottle + Gas Equipment and Gas Bottle has no shipping method show message 2

    I have changed the messages so it shows what I need.

    // Change the WooCommerce ‘No shipping methods available’ message

    add_filter( ‘woocommerce_cart_no_shipping_available_html’, ‘mh_no_shipping_message’, 10, 2 );
    add_filter( ‘woocommerce_no_shipping_available_html’, ‘mh_no_shipping_message’, 10, 2 );

    function mh_no_shipping_message() {

    $message = ‘This gas bottle can NOT be shipped to your address. Please call Phone Number to discuss delivery options. Thank you.’;
    $message2 = ‘Unfortunatly this gas bottle can NOT be shipped to your address. We can ship the other products. Please either remove the gas bottle and proceed to checkout or call us on Phone Number to discuss delivery options. Thank you.’;
    $pcode = WC()->customer->get_shipping_postcode();
    if (mb_substr($pcode, 0, 2) == ‘GY’ || mb_substr($pcode, 0, 2) == ‘JE’) {
    return ‘<p>’ . __( $message2, ‘woocommerce’ ) . ‘</p>’;
    }else{
    return ‘<p>’ . __( $message, ‘woocommerce’ ) . ‘</p>’;
    }
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Complex Shipping Issue’ is closed to new replies.