I have tried below code. However its working fine but other products for which custom attribute is not being added from admin, I am not able to add to cart such products.

enter image description here

  • Can you please check logs. Is there any logs related to add to cart? Commented Jun 3, 2021 at 7:01
  • Try to add code instead of screenshot. Commented Jun 3, 2021 at 7:01
  • cache_invalidate: {"method":"GET","url":"localhost/magento_23/men/tops-men/…": This is what I am getting in debug log Commented Jun 3, 2021 at 7:07

1 Answer 1


Put code in below condition

if($percentage != ''){
     // here will go line no 13 to 21 code  

hope this helps you :)

  • It's not working.still same issue Commented Jun 3, 2021 at 6:45
  • answer updated. please try this Commented Jun 3, 2021 at 14:08
  • Now it's working fine for simple and configurable products. But it's not working for other products like configurable and grouped product. Commented Jun 7, 2021 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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