• Resolved shridharkagi

    (@shridharkagi)


    Dear Forum,

    Here is my query.

    I have different shipping methods.
    Ex:
    1. Shipping Using Customer A/C [Please enter your Fedex/ DHL /Other Courier Name and Account Number in the “Courier Info” Box above.]

    2. Free Shipping in India
    3. International

    Now all the above are showing for all countries.

    When the Billing country is India and shipping country is India –> I want 2nd option. (Free Shipping in India)

    When the Billing country and is not India and shipping country is any –> I want 1st and 3rd Options.

    (Screenshot Link: https://ibb.co/v38z524 )

    Can you guide/ share me any hooks for the same which I can use in functions file.

    Much appreciated.

    Regards,
    Shridhar K

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support abwaita a11n

    (@abwaita)

    Hi @shridharkagi,

    Just to check, have you tried using Shipping Zones already? The conditions will check the shipping country, if that’s the main consideration here.

    • You can start by creating a shipping zone for India and then add the free shipping method to it. Make sure that this shipping zone is the first one on the list at WooCommerce → Settings → Shipping
    • You can then use the zone for everywhere else to add the courier/international shipping options. Note that the courier options will require you to add the plugins for the different carriers. You could check the ones available on our marketplace: https://woocommerce.com/product-category/woocommerce-extensions/shipping-methods/shipping-carriers/

    Hope this helps.
    Thanks.

    Thread Starter shridharkagi

    (@shridharkagi)

    thanks for this @abwaita.

    I was using shipping zones before. I had created a shipping zone as India for free delivery.

    In this case what happens is.

    let say customer is form US (Billing) He wants to ship to India. Since India comes under Free Delivery so for the US customer, shipping India will show him “Free Delivery”.

    In my case I want to show International for him.

    I want free delivery only when billing and shipping is in India. Hope you got my concern.

    Thank you for your time.

    Plugin Support abwaita a11n

    (@abwaita)

    Thanks for your explanation.

    Well, I can recommend the Conditional Shipping and Payments plugin, which has options for creating shipping conditions based on billing and shipping country.

    You could check the docs or create a ticket with us for additional info.

    Otherwise, for the custom coding route, I would recommend consulting with the WooCommerce Customizations Partners.

    I’ll also leave the thread open to invite anyone who can help with the custom code to post here.

    Thanks.

    Thread Starter shridharkagi

    (@shridharkagi)

    Here is what I tried and it’s working.

    add_filter( ‘woocommerce_package_rates’, ‘free_shipping_method_enable_only_india’, 100, 2 );
    function free_shipping_method_enable_only_india( $rates, $package ) {
    $country = WC()->customer->get_billing_country();
    $condition = $country == “IN”;

    if ( $condition ){
    $targeted_rate_id = ‘free_shipping:4’;
    unset($rates[$targeted_rate_id]);
    unset($rates[‘table_rate_shipping_international-1-unit’]); //to unset international
    unset($rates[‘table_rate_shipping_international-2-units’]);
    unset($rates[‘table_rate_shipping_international-3-5-units’]);
    unset($rates[‘table_rate_shipping_international-6-10-units’]);
    unset($rates[‘table_rate_shipping_international-11-20-units’]);
    unset($rates[‘table_rate_shipping_international-20-units’]);

    }
    else{

    unset($rates[‘free_shipping:16’]); //to unset free

    }
    //}
    return ! empty( $free ) && ! $condition ? $free : $rates;
    }`

    Reference: https://stackoverflow.com/questions/64678799/conditionally-hide-shipping-methods-in-woocommerce?answertab=votes#tab-top

    Thank you.

    Plugin Support abwaita a11n

    (@abwaita)

    Glad to hear that you were able to find a solution – thanks for letting us know!

    I’ll mark this thread as resolved now. If you have any further questions, you’re welcome to create a new thread.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conditionally Hide Shipping method’ is closed to new replies.