I have a template to show a Woocommerce product on various pages on my website. This includes the add to cart/select options button added as a dynamic data {woo_add_to_cart}in a text element.
On any ânon-woocommerceâ pages this shows up with correct styling but on pages such as product archive and shopping cart diffrent syling is applied. Refer to the screenshots below.
Thanks for the links!
I agree with you that the styling should be the same everywhere - both for the dynamic data tag and for the add to cart element.
Especially if you have created custom styles for the WooCommerce button in the theme styles. These should determine the styling everywhere.
You can temporarily fix this by assigning the .woocommerce class to the section containing your products on the non-woocommerce pages. Then the styles follow the theme styles » woocommerce button settings, and you can style them globally.
Applying the .woocommerce class indeed helps to make the styling consistent across all pages where the template is used. Unfortunately this removes flexibility to have the add to cart button / select options button in the template styled differently from other WooCommerce buttons. How could I address this?
Your homepage does not have the .woocommerce class.
The style of woocommerce button is made .woocommerce . button {style:style) but as the homepage does not have woocommerce in the body class, this wonât work in homepage, to fix this you can add the following css.
This will work only on homapge, some changes are required if you want the code to be working on other pages that are not woocommerce pages, this will also work only with variable products, some changes will be required in order for it to work with simple products too. You can put the code in the homepage CSS ori your style, anywhere works.
To style the button the same as on all other woocommerce buttons the same result can be achieved by adding the â.woocommerceâ to the element. Refer to the image below.
However what I need is this specific button to be styled differently form the other woocommerce buttons regardless on what page it is displayed. The desired styling is applied in the template but not displayed on any âWoocommerce pageâ since the .woocommerce class seems to be added for some reason.
At first glance, I would add a custom class and style it using custom CSS, where I can make my custom class more specific so it is âstrongerâ than .woocommerce .button. Check the front end, see where your class applies and chain the selectors accordingly, so it gets a higher specificity.