Best practice for customizing cart item price display from an app?

Best practice for customizing cart item price display from an app?

paro22
Shopify Partner
4 0 0

Hi there,

 

I'm working on an app for try-before-you-buy logic. As part of that, I need to customize a few different areas of a customer's theme (also see docs here😞

  • Price
  • Add to cart/Buy button
  • Cart items (to show updated price)

For example, if I want to show a line item as $0 in the cart because it's a free trial, it looks like I would need to copy-paste ~400 lines of code from the "main-cart-items.liquid" and then another ~400 lines from the "main-cart-items.liquid" (Dawn theme) into my app code just so that I can update one line.

 

This doesn't seem like a very maintainable pattern. How can I as an app developer ever be sure that my copy-pasted code will work across themes?

 

What am I missing?

Replies 2 (2)

NomtechSolution
Astronaut
1245 113 159
  1. Utilize theme hooks: Some themes provide hooks or events that you can tap into to inject your app's functionality without modifying the theme's code directly. By utilizing theme hooks, you can add your custom logic and modify specific areas without the need for extensive code duplication.

  2. Provide instructions for manual theme modifications: In cases where customization options are limited, you can provide detailed instructions to the merchant on how to modify their theme's code manually.

paro22
Shopify Partner
4 0 0

Thanks for the quick reply. I have a couple of follow-up questions:

 

  1. It doesn't sound like theme hooks are universal, correct? So if I want to sell my app in the marketplace and have it work for all themes, there are no hooks that work across the board for all/most themes?
  2. Is there an easy way to tell whether a theme has hooks that I can use? I couldn't really find anything obvious aside from reading all the actual theme code. For example, I  randomly stumbled upon how Dawn sends events for a couple of scenarios (not including the one I'm interested though).