0

I'm a very new to Magento2. I'm stuck with display the new shipment option show/hide.

I have created a new shipment method programmatically and name it "Same Day Delivery" and also I have created a Product Attribute programmatically and name it "Same Day Delivery Available: (Yes/No).

I would like to add the restriction on the Checkout page - If all items in CART have (Same Day Delivery Available as Yes). Then display the new shipment option or hide them in the shipment selection section.

Two things i have done,

  1. Shipment method programmatically
  2. Product Attribute programmatically

I need shipment option have to show based on product attribute.

Here is my coding:strong text https://github.com/balajimrv/app

Kindly help me. Thank you in advance.

1
  • In your model career file "collectRates " method you can getAllVisibleItems and you can add condition if for any of product has "Same Day Delivery Available" is not available then you can simply "return false;" it will not call your shipping on cart/checkout. May 13 at 5:20

1 Answer 1

0

You need to get cart items in your collectRates function and return false if your attribute value is No. you can get your attribute Same Day Delivery Available value by product id easily.

2
  • get attribute by product id is very old and bad practice. nowdays magento giving us feature for catalog_attribute.xml for achive this kind of requirement. May 13 at 5:18
  • could you send the full code? please.... help me May 16 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.