Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 UTC on 18 March 2024, to get $100 off your ticket.
If like me you need to clear the shipping line item when going back from review to shipping (or any other path back to shipping) you can use the rule below to do so.
This can be handy in various use cases like when needing to have shipping calculation based on order total.
The rule is
Event:
After updating an existing commerce order
Conditions:
Data comparison: commerce-order:status = Checkout: Shipping
Shipping line item exists
Action:
Delete all shipping line items from an order
Comment | File | Size | Author |
---|---|---|---|
#1 | commerce_shipping_clear_shipping.txt | 558 bytes | guy_schneerson |
Comments
Comment #1
guy_schneerson CreditAttribution: guy_schneerson commentedAttaching an export of the rule, hope other find it useful.
Comment #2
Horroshow CreditAttribution: Horroshow commentedUseful! Thanks!
Comment #3
svouthi CreditAttribution: svouthi commentedI was excited to see this because I have rules which add fees based upon shipping cost/type and things get messy when a user backs out of Checkout Review and returns to Checkout or Shipping with all those line items staying present. However, this rule isn't working for me. Instead of removing the shipping line item if the user leaves the Checkout Review page, the shipping line item is removed between adding it on the Shipping page and arriving at Checkout Review (such that there is no shipping charge.)
I experimented with changing the data comparison to Checkout:Review instead of Checkout:Shipping, but the behavior is the same. When I change it to Checkout:Checkout, the shipping line item doesn't get cleared.
Comment #4
calebyoder CreditAttribution: calebyoder commentedYes, I struggled with this issue for hours as well. :( What finally seems to be working fairly good is when I added the following condition.
NOT Data comparison: commerce-order-unchanged:status = Checkout: Shipping
Thanks for sharing this, guy_schneerson!
-Caleb
Comment #5
barry6575 CreditAttribution: barry6575 commentedConfirmed #1 & #4 solved the issue for me. Thanks!
Comment #6
CaptChawrls CreditAttribution: CaptChawrls commentedConfirmed #1 & #4 solved the issue for me, too. However, since my shipping choice option had been moved to step 1 of checkout (I was trying to limit the number of stages of checkout), I had to modify #4 to point to the correct step in the process (i.e. Checkout: Checkout instead of Checkout: Shipping).
Before I added this rule, when the user went to step 1 of checkout and then returned to the view cart page, there was a blank line item (i.e. no title, only claculated shipping price and a remove button) appearing that wouldn't go away. Additionally, it also caused the update button to generate a fatal error when clicked -- EntityMetadataWrapperException: Unknown data property commerce_product. in EntityStructureWrapper->getPropertyInfo() ...