Woocommerce hook to display offers text after shop loop item

woocommerce_after_shop_loop_item woocommerce hook

WooCommerce provides different hooks for their shop page, product category pages, cart page, and checkout page. These hooks allow us to place our content or offers in various locations on these pages.

Woocommerce hook to display offers text

If you are using woo-commerce for your online store, and if you are looking to display custom offers text after shop loop items to attract your customer to place multiple orders then this article is very useful for you.

In this post, we will learn about calculating extra discount offer amount based on product regular or sale price and display it after the price on the shop page or product category page.

woocommerce_after_shop_loop_item

As you can see in the above screenshot, I am displaying an extra 35% off on every product’s regular or sale price.

But you can see in the image, I am not displaying any discount percentage (%).

Sometimes customers want to know the extra discount amount instead of the discount percentage.

How discount will apply on cart page

Now the point is, how this discount will apply on the cart page?

So, now there are multiple solutions:

  1. You can display discount coupon of 35% and customer will use it.
  2. You can automatically add discount coupon on cart page.

So here we will calculate the 35% extra discount amount based on the product’s current regular price or sale price and display the extra discount amount after the shop loop item.

woocommerce_after_shop_loop_item hook

We will use the woocommerce_after_shop_loop_item hook. The woocommerce_after_shop_loop_item hook is placed content below the price. This hook is defined in the content-product.php template file in WooCommerce.

To calculate and display the extra discount offer amount, paste the below code in your theme functions.php file

in the above code, you can see we are multiplying 0.35 with regular or sale price for a 35% discount amount.

If you want to apply 40% off then you need to replace 0.35 with 0.40.

Are you want to get implementation help, or modify or extend the functionality of this script?

A Tutorialswebsite Expert can do it for you.

Different discount amount condition based on category

If you want to show different discounts on a specific category, then you can also add conditions for the category to apply different discount amounts.

Let’s update the above code and add conditions to check the category id and add the discount for this category.

In the above code, we are checking the category page. if the current page is a category page then we are getting the current category page id.

We defined the category id as 185 on which we want to apply a 40% discount. Otherwise 35% discount will apply on another category page.

Are you want to get implementation help, or modify or extend the functionality of this script? submit your paid request

Also Read: How to Charge Extra Cash on Delivery Fee for Woocommerce

Conclusion

Well, In this article you will get the complete steps to apply the Woocommerce hook to display offers text after shop loop item. You can extend the functionality as per your requirement. I hope you found this tutorial helpful for your project. Keep learning!.

Related posts