Modifying 'Add to cart' button text

Created on 27 December 2024, 7 days ago

Problem/Motivation

Report received & verified as reproducible at https://www.drupal.org/project/commerce_cart_redirection/issues/3496009 🐛 Button looses CSS classes, when activating Redirection Active


The Commerce Cart Redirection module allows the site admin to arbitrarily modify the text of the Add to cart button, this causes the add to cart button to lose its theming.

Thoughts

It seems that the class addition depends on the button text being "Add to Cart" fairly late in the rendering process.

In the Commerce Cart Redirection module, I modify the button text earlier in the workflow ( in a form_alter ), which results in the classes not being added as expected. I’ve implemented a workaround in the 3.3.x-dev version using string substitution on the rendered button markup in a post_render callback. It's functional but it's not a feel good solution and it may not be reliable.

Questions and Assistance Needed

  • Is there a recommended way within the Belgrade theme to ensure classes are applied to the button regardless of text changes?
  • Could this behaviour be decoupled from the button text, such as targeting the button via selectors or hooks?
  • Are there any hooks or methods I could use to safely modify the button text without interfering with class additions?

I'd like to make the module work with the Belgrade theme while maintaining flexibility for sites that already use custom button text. Any insights or guidance you can provide would be greatly appreciated.

Thanks!

💬 Support request
Status

Active

Version

2.0

Component

Code

Created by

🇳🇿New Zealand andyd328 Lyttelton, NZ 🇳🇿

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024