Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce targeting the shop page only with css

This is what I need to do:

  • To target only the main shop page with css (a specific custom class I created as mentioned below).

This is what I've done and tried so far:

  • I have an override template of archive-product.php in my child theme.
  • In this override template I've added a div with a custom class custom-shop-class just before the product loop start, because I want to target the looped products specifically.
  • I tried targeting with class page-id-4 because if I hover over the "shop" page in wp-admin, it gave me http://.../post.php?post=4&action=edit

The problem I'm having is as follows:

  • From what I've discovered is that the same archive-product.php template is being used in the other various shop pages and not only in the main "shop" page (correct me if I'm wrong), so when I target my custom-shop-class with CSS, it affects all the other shop pages using the same template file, and it must not.
  • There is no unique identifier or class specifically for the shop page, something like the page-id-?? class in the body tag (as in the usual WP pages).

Any suggestions on the best method/solution?

Thanks in advance, Mario.

like image 531
Mario Avatar asked Jun 01 '16 20:06

Mario


People also ask

How do I add CSS to WooCommerce product page?

Navigate to Appearance > Customize in your WordPress dashboard. Scroll down and click “additional CSS” in the menu. You will find a text field to add your CSS codes.

How do I change the shop page design in WooCommerce?

To do this, go to Appearance → Customize → WooCommerce → Product Catalog. Change the 'Shop page display' option to 'Show categories & products'. This will list all your categories in a grid layout at the top of the WooCommerce shop page, with a product table listing the products underneath.


1 Answers

Set a conditional statement to check for the primary shop page, then echo the div in question if that statement evaluates to true.

WooCommerce Conditional Tag for main shop page:

is_shop()

Example

if (is_shop()) {
echo "<div class='custom-shop-class'></div>";
} else {
echo "<div class='custom-product-category-class'></div>";
}

Alternatively:

<?php if (is_shop()):?>
<div class="custom-shop-class"></div>
<?php else: ?>
<div class="custom-product-category-class"></div>
<?php endif;?>

Conditional Tags | WooThemes Documentation

like image 158
UncaughtTypeError Avatar answered Sep 28 '22 06:09

UncaughtTypeError