0

I want to set a custom style for displaying prices on sale in woocommerce archive page. I could do that in single-product.php file but in archive page its just wc_get_template_part( 'content', 'product' ); and there is no reference to find it.

How can I find the html template and set a custom css class for on sale products in archive page?

1 Answer 1

0

In your Theme you should have several template files with names beginning with "content" followed by a hyphen, a unique name, and .php, e.g. "content-xxx.php". Sometimes they may be in a sub-folder called something like "template parts".

That's where you would find the content-product.php file and within it the loop that you can modify to add your custom style declaration.

However I would strongly encourage you to be certain you're modifying a CHILD Theme you've created, otherwise Theme updates will overwrite your edits.

Alternatively, you can add some code to your (Child) Theme's functions.php, or better yet a custom plugin that exists in your Plugins folder not your Theme folder (to make it Theme agnostic), to add classes.

You can do this using Filters, I've done it to add classes to the Body and Post class, but you can get more granular as you need to. See this page for some examples:

https://developer.wordpress.org/reference/functions/body_class/

Scroll down to see the examples, you could target your template easily enough.

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.