cancel
Showing results for 
Search instead for 
Did you mean: 

Restrict free shipping with coupon code

Restrict free shipping with coupon code

I'm trying to configure my checkout so that if any coupon code is used, free shipping is disabled - basically the customer either receives free shipping or a discount, but not both. In the delivery methods settings it seems free shipping is either on or off based on a threshold with no other parameters. On the cart rule side, I have free shipping set to no, but it still allows the customer to receive both. How can I go about configuring this? If it matters, free shipping is only via USPS on orders over $39, with options to pay for faster delivery.

4 REPLIES 4

Re: Restrict free shipping with coupon code

@Kyleroll208992 

You can hide the free shipping programmatically by following the below code:

1. Create a plugin in di.xml file and use this below code.

<type name="Magento\Shipping\Model\Shipping">
    <plugin disabled="false" name="Vendor_Extension_Model_Shipping" sortOrder="10"
            type="Vendor\Extension\Plugin\ApplyShipping"/>
</type>

2. Create a plugin file in Vendor/Extension/Plugin.

<?php

namespace Vendor\Extension\Plugin;

class ApplyShipping
{

    public function __construct()
    {

    }

    public function aroundCollectCarrierRates(
        \Magento\Shipping\Model\Shipping $subject,
        \Closure $proceed,
        $carrierCode,
        $request
    )
    {
            // Enter Shipping Code here instead of 'freeshipping'
        if ($carrierCode == 'freeshipping') {
           // To disable the shipping method return false
            return false;
        } 
           // To enable the shipping method
            return $proceed($carrierCode, $request);
    }
}

You can get and check the coupon code with the below code:

 

    "$this->chcekoutSession  is object of \Magento\Checkout\Model\Session"

    $couponCode = $this->checkoutSession->getQuote()->getCouponCode();

 

 

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: Restrict free shipping with coupon code

Free Shipping is one of the promotion programs you can set up on Magento 2 when customers don’t need to pay any fee for your delivery. Unlike traditional shopping where customers can come to the store and pick up items directly, online shopping requires them to pay the extra shipping fee, which can become a burden for them to make purchase decisions. Click Here For More Info Therefore, offering free shipping promotion can make them feel comfortable to purchase more - a great way to increase conversion rates and boost sales, isn’t it?

From Magento 2 Shopping Cart Rule settings, depending on conditions you set, the Free Shipping can be applied for any order when all conditions are met. Simultaneously, you are able to generate an coupon code, that allows the customers to use coupon or not to apply the  Free Shipping Promotion. 

4 Steps To Set up Free Shipping Promotion in Magento 2

  • Step 1: Activate Free Shipping
  • Step 2: Activate Free Shipping in the Carrier Configuration
  • Step 3: Set a Shopping Cart Price Rule
  • Step 4: Check the Rule

Step 1: Activate Free Shipping

Please activate the Free Shipping and finish its settings in your store’s configuration.

    • On the Admin Panel, Stores > Settings > Configuration.
    • Under Sales, select Shipping Methods.
    • Open the Free Shipping section, follow the guides:
      • Enable the Free Shipping by choosing Yes.
      • Add the Title.
      • Enter the Method Name to make clear about the shipping method. With Free Shipping, type the Free.
      • Offer the Minimum Order Amount for the shipping.
      • Enter a error message in the Displayed Error Message box that will appear if Free Shipping is not available.
      • Set Ship to Applicable Countries to one of two options:
        • All Allowed Countries : Free Shipping is supported for all countries.
        • Specific Countries: Free Shipping is only supported for selected countries.
        • Set Show Method if Not Applicable to Yes if you want to show Free Shipping all time.
        • Set the Sort Order on the Shipping Method on the checkout page.
        • Save Config to finish.

Re: Restrict free shipping with coupon code

I completely agreed with @dolgeneral0ea6  Because the same process i have been followed to get rid off from my issue on instantly why don't you try and follow the same thing might be it will be work for you

Re: Restrict free shipping with coupon code

Block certain methods of the shipping carrier
Create restrictions based on customer’s shipping data
Restrict shipping by various product attributes and order info
Use customer groups and store views as a restriction base
Disable or allow delivery with coupon