Search the site:

Home Blog WooCommerce Shop Page Hooks: Visual Guide with Code Snippets

WooCommerce Shop Page Hooks: Visual Guide with Code Snippets

WooCommerce has lots of different hooks for their shop page, product pages, cart page & checkout page. These hooks help us to add our content in different places on these pages. We saw the different cart page hooks & checkout page hooks earlier.

In this post, we will learn about different WooCommerce Shop page hooks and where they are placed on the page. The examples below are tested  with WooCommerce version 3.3 .

woocommerce_before_main_content

Shop

woocommerce_archive_description

woocommerce_before_shop_loop

Showing all 4 results

  • woocommerce_before_shop_loop_itemwoocommerce_before_shop_loop_item_titlewoocommerce_shop_loop_item_title

    Product Title 1

    woocommerce_after_shop_loop_item_title

    €5,00

    woocommerce_after_shop_loop_item

    Add to cart

  • woocommerce_before_shop_loop_itemwoocommerce_before_shop_loop_item_titlewoocommerce_shop_loop_item_title

    Product Title 2

    woocommerce_after_shop_loop_item_title

    €5,00

    woocommerce_after_shop_loop_item

    Select options

  • woocommerce_before_shop_loop_itemwoocommerce_before_shop_loop_item_titlewoocommerce_shop_loop_item_title

    Product Title 3

    woocommerce_after_shop_loop_item_title

    €1,00

    woocommerce_after_shop_loop_item

    Add to cart

  • woocommerce_before_shop_loop_itemwoocommerce_before_shop_loop_item_titlewoocommerce_shop_loop_item_title

    Product Title 4

    woocommerce_after_shop_loop_item_title

    €1,00

    woocommerce_after_shop_loop_item

    Select options

woocommerce_after_shop_loop

woocommerce_after_main_content

The WooCommerce Shop page contains the following hooks:

  1. woocommerce_before_main_content
  2. woocommerce_archive_description
  3. woocommerce_before_shop_loop
  4. woocommerce_before_shop_loop_item
  5. woocommerce_before_shop_loop_item_title
  6. woocommerce_shop_loop_item_title
  7. woocommerce_after_shop_loop_item_title
  8. woocommerce_after_shop_loop_item
  9. woocommerce_after_shop_loop
  10. woocommerce_after_main_content

1. woocommerce_before_main_content

The woocommerce_before_main_content hook is placed at the start of the shop page. This hook is defined in the single-product.php template in woocommerce.

Let’s see an example to show a banner at the top to inform customers about that there is a 10% discount on all the items in the shop.

It will look like this –

2. woocommerce_archive_description

The woocommerce_archive_description hook is placed after the ‘Shop’ header title on the shop page. This hook is defined in the archive-product.php template file in WooCommerce.

This hook defines itself. We can add some description about the shop page using it. Let’s take an example of a shop which sells TV sets. We will add some description like – ‘Shop from a wide selection of LED TVs..’ below the shop title.

3. woocommerce_before_shop_loop

The woocommerce_before_shop_loop hook is placed before the products list on the shop page. This hook is defined in the archive-product.php template file in WooCommerce.

For example, we will add a title before the products list called ‘New & Trending’.

4. woocommerce_before_shop_loop_item

The woocommerce_before_shop_loop_item hook is placed on top of each product in the list. This hook is defined in the content-product.php template file in WooCommerce.

Whatever we define here will apply to all products in the list on the shop page. For example, lets add a tag of ‘New & Trending’ to all products.

 

 

If you want to add it to a single product, you can do so by adding a condition to check for the product ID.

5. woocommerce_before_shop_loop_item_title

The woocommerce_before_shop_loop_item_title hook is placed above the product image. This hook is defined in the content-product.php template file in WooCommerce.

Let’s add a tag of ‘Best Seller’ to some specific products with ID 57 & 59.

6. woocommerce_shop_loop_item_title

The woocommerce_shop_loop_item_title hook is placed above the product name. This hook is defined in the content-product.php template file in WooCommerce.

There can be many uses of this hook. Lets add the stock available for each product.

7. woocommerce_after_shop_loop_item_title

The woocommerce_after_shop_loop_item_title hook is placed below the product name. This hook is defined in the content-product.php template file in WooCommerce.

Lets display the product categories under the product name.

8. woocommerce_after_shop_loop_item

The woocommerce_after_shop_loop_item hook is placed above the ‘Add to Cart’ name. This hook is defined in the content-product.php template file in WooCommerce.

We will show our customers a few recommended products.

9. woocommerce_after_shop_loop

The woocommerce_after_shop_loop is placed just below the product list. This hook is defined in the archive-product.php template file in WooCommerce.

Let’s add a featured product at the bottom using this hook –

10. woocommerce_after_main_content

The woocommerce_after_main_content is placed after all the page content. This hook is defined in the single-product.php template file in WooCommerce.

You can add support related description and link to your support page here.


Conclusion

These are just some simple examples to explain how we can use various hooks defined by WooCommerce. You can create lots of complex things to make your store more appealing to customers.

Browse more in: Code Snippets, WooCommerce Guide, WooCommerce How Tos, WooCommerce Tutorials

10
Leave a Reply

avatar
5 Comment threads
5 Thread replies
3 Followers
 
Most reacted comment
Hottest comment thread
6 Comment authors
GiovanniTapasdlxFrançoisMathiasRashmi Malpande Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest
Notify of
Henning
Guest

Great content!
For me Woocommerce can be very difficult, but also deliver satisfying structure and overview.

I will definitaly look into some of these hooks you mention

Mathias
Guest

Wow! I just have to say thank you. You saved me a lot of time – this was excactly what i was looking for. I’m going to share you post, as i know a few more that would benefit from these hooks.

And FYI, as someone that is mediocre in coding, this was easy understandable.

Thank you!

François
Guest
François

Hi,
Thank you for this article it’s really helping a lot.
One question though. What is the difference between using the “woocommerce_archive_description” hook and simply using the editing panel of the shop page? Is there any advantage ?
Writing the description of the page in that panel does the same..
Thanks

Tapasdlx
Guest

Great read.

I have issues with the new wordpress version, regarding this?

Giovanni
Guest
Giovanni

Hello, I try those hook, but not all working. In my site, woocommerce_after_shop_loop_item and woocommerce_shop_loop_item_title doesn’t working. Instead, woocommerce_after_main_content works perfectly. Moreover, how is it possible to use more functions at the same time?

from purchased

Subscribe Now