Installation of Magento 2 Payment & Shipping Restriction by Webkul

Carmella Blick
8 min readApr 11, 2023

Using Magento 2 payment and shipping restriction module, the admin can assign the shipping and payment methods to products and categories.

Sometimes the admin wants to restrict a few of the shipping and payment methods for some products and category types.

So, instead of completely disabling the shipping and payment methods for the store, restrict the shipping and payment methods that the admin doesn’t wish to use for particular products and categories.

During the checkout process, the customer can view the assigned shipping and payment methods to place an order.

Note:

  • The extension will not create any new shipping and payment methods for you.
  • The module functionality will not work for the order created from the admin panel.

Wonder How the Module Works? Watch the below Video

Installation

Customers will get a zip folder and they have to extract the contents of this zip folder on their system. The extracted folder has an src folder, inside the src folder you have the app folder. You need to transfer this app folder into the Magento2 root directory on the server as shown below.

After the successful installation, you have to run these commands in the Magento 2 (Adobe Commerce) root directory.

First command –

php bin/magento setup:upgrade

Second Command –

php bin/magento setup:di:compile

Third Command –

php bin/magento setup:static-content:deploy

Fourth Command –

php bin/magento indexer:reindex

Once, after running the commands, you have to flush the cache from the Magento admin panel by navigating through System->Cache management as shown below.

Multi-Lingual Configuration

For Multilingual support, please navigate to Store>Configuration>General >Locale Options. And select your desired language from the Locale option.

Module Configuration

After the module installation, the admin can configure the module settings by navigating to the Stores->Settings->Configuration->Webkul->Shipping and Payment Restriction as shown below.

Here, the admin will:

  • Enable Module on Frontend — Set the option to Yes if want to display the restricted shipping and payment methods only on the front-end.
  • Else set the option to No if want to display all the shipping and payment methods.

And, lastly hit the Save Config button to save the configuration successfully.

Category — Assign Shipping & Payment Methods

The admin can restrict the different payment and shipping methods for each category as shown below.

On the category edit page, the admin will have two fields:

  • Select Shipping Method- Choose the shipping methods wants to enable for that particular category.
  • Select Payment Method- Choose the payment method wants to enable for that particular category.

And, lastly hit the Save button to save the category successfully.

Note:

  • The admin needs to configure the payment and shipping methods for each category individually.
  • Further, the admin can configure the different payment and shipping methods for the parent and the child category.
  • The admin can also restrict the shipping and payment for the categories which were existing before the installation of this module.

Product — Assign Shipping & Payment Methods

The admin can even restrict the different payment and shipping methods for each product as shown below.

On the product edit page, the admin will have two fields:

  • Select Shipping- Choose the shipping methods wants to enable for that particular product.
  • Select Payment- Choose the payment method wants to enable for that particular product.

And, lastly hit the Save button to save the product successfully.

Note:

  • The admin needs to configure the payment and shipping methods for each product individually.
  • The admin can restrict the payment and shipping methods for the product types — Simple, Configurable, Virtual, and downloadable.
  • Moreover, the admin can restrict the shipping and payment for the products which were existing before the installation of this module.
  • The Mapped shipping and payment method should be selected else there will be no payment method displayed for the mapped shipping selected.

Payment Shipping Mapping

The admin can map the payment method with the shipping methods by navigating to payment shipping mapping section and the following mapping list will be displayed as shown in the image below.

The admin can create new mapping from the Add Mapping section and select the desired shipping method and payment method that is needed to be saved as shown in the image below.

Front-End

Now at the front-end, the customer can view the restricted shipping and payment methods while placing the order. On the cart page, the customer can view the enabled shipping methods only.

And accordingly, the customer will select the shipping method when proceeding further.

While making the payment, the customer can choose the payment method from the enabled ones only.

The module allows Magento 2 payment restrictions and shipping method restriction on the product and on the category.

Note:

  • If the admin has not restricted any shipping and payment methods on products then, the control will automatically check for restrictions on the category of that product.
  • If no restriction is applied to the category as well, in that case, all the active shipping and payment methods will be available at checkout.
  • The module supports CheckOut with Multiple Addresses as well.

Case 1: What If A Single Product In The Cart Belongs To Multiple Categories?

The shipping and payment restriction made on the product has a higher priority than that of categories. So, in this case, firstly it would check the shipping and payment method assigned to the product. If not assigned, then it will automatically check for restriction on the categories of that product and does the union of payment and shipping methods of the multiple categories. Union of shipping and payment methods will be displayed at the checkout page.

Case 2: What If The Shopping Cart Has Multiple Products (Each Product Belongs To Multiple Categories) With Different Shipping And Payment Method Enabled?

The shipping and payment restriction made on the product has a higher priority than that of categories. So, in this case, firstly it would check the common payment and shipping methods among the multiple products in the cart and accordingly will display them at the checkout. If no shipping & payment method is assigned to products then it will automatically check for shipping and payment method restrictions on the categories. For each product, it does the union of payment and shipping methods of the categories it belongs to. Secondly, will check the common payment and shipping methods among the multiple union sets created for each product. And those common shipping and payment methods will be displayed at the checkout page.

Case 3: What If The Enabled Shipping And Payment Methods Don’t Work For The Location From Where The Customer Is Placing The Order?

In this case, it first checks the shipping and payment method assigned to the product based on the customer’s location and accordingly displays them at checkout. If for a product, restricted shipping and payment method is not applicable as per the customer’s location, then, the shipping and payment method restriction of the category will be displayed. If the shipping & payment restriction is applicable to a product, then, payment and shipping restriction is never applicable to that category-based product. Let us understand this through an example which is given below.

For instance, there is a product named Product-1 that needs to be shipped to New York and Germany. The shipping and payment method mapping is defined for Product-1 is USPS and COD, respectively. One can see that the USPS shipping shall be applicable to Product-1 which needs to be shipped to New York. At the same time, if the same product, Product-1 is to be shipped to Germany. Moreover, if by any chance, the USPS shipping is not applicable, then there will be no shipping and payment methods applicable for the location Germany on the checkout page.

Case 4: What If Two Or More Products Are Added In The Cart, Each Having Separate Shipping & Payment Methods Mapped On It?

Let’s suppose there are two products X and product Y. For product X, enabled shipping methods are (Free shipping, Table rate & Flat rate ) and (Check/Money Order, Bank Transfer Payment & Cash on Delivery ) are its selected payment methods.

Whereas for the product, Y (Flat rate and Free shipping) are the enabled shipping methods and (Check/Money Order, Bank Transfer Payment, Cash on Delivery & PayPal Billing Agreement ) are its selected payment methods. Additionally in the backend Free shipping has been mapped with COD.

As a result, when a customer for an instance adds these two products X and Y into his shopping cart only the shipping rates which are commonly present for both products will be visible to the customer, in this case, (Flat rate and Free shipping). Further, consider that the customer opted for Free shipping since it is originally mapped with the COD. Therefore only cash on delivery will be visible to the customer. Or if the customer picks Fixed rate shipping and note since we haven’t mapped this with any of the payment methods. Therefore, here all the common payment methods will be visible to the customer. Which are (Check/Money Order, Bank Transfer Payment & Cash on Delivery ) for this case.

Explore the Adobe Commerce Cloud development services by Webkul. You may also browse our quality Magento 2 extensions.

Originally published on https://webkul.com/blog/magento2-payment-shipping-restriction/

--

--

Carmella Blick

A digital marketer helping business to discover the right digital marketing strategy. And sometimes a blogger who love to express views on popular market trends