Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've added some custom fields to customer billing, and I'm using tokens for those in the checkout completion message and in notification emails. For non-required fields, if the customer leaves the field empty, the token itself is output, ie "[commerce-order:commerce-customer-billing:field-foo]". Not ideal.
I guess the "clear" option isn't being passed when replacing these field tokens, and I'd like to fix this. For starters I'm trying to figure out where the token replacement happens - in a commerce module, or is core field module responsible?
Comment | File | Size | Author |
---|---|---|---|
#2 | clear_tokens_with_no_values-1665060-2.patch | 733 bytes | vasike |
Comments
Comment #1
John Pitcairn CreditAttribution: John Pitcairn commentedOK, for the completion message it's commerce_checkout.checkout_pane.inc, line 143:
A change to:
Will prevent the empty token placeholder from being rendered. But this will also change behavior if anyone was relying on the empty token placeholder for anything.
Comment #2
vasikeand here the patch for John Pitcairn solution.
Thank you Sir.
Comment #3
joshmillerBug confirmed; Patch applied cleanly; Bug fixed.
Note: Should you try and figure this bug out using rules as opposed to using the checkout completion, you'll find that Rules' implementation of token_replace() also has this flag that is missing. That is, if you use a [token], it doesn't silently remove it from the "send mail" or "system message" actions. That is another patch and another module completely.
Comment #4
rszrama CreditAttribution: rszrama commentedAlrighty, added the clear as patched.
Comment #5
brephraim CreditAttribution: brephraim commentedI'm still getting this in my order confirmation messages after the patch has been applied: [message:message-commerce-order:commerce-customer-shipping:commerce_customer_address]
Comment #6
rszrama CreditAttribution: rszrama commentedI used your precise token on a site that doesn't even have Shipping installed, and I do not see the token in the checkout completion screen. That said, you should note that joshmiller's comment above explains that we could only fix this for our checkout pane's message and not other messages or e-mails generated by Rules. Rules would have to be patched for that.
Comment #7
joshmillerSee #1559844: Field token is not replaced when fields are blank