Reputation: 13
This is what I have right now to make text display underneath the product price and information on the shop page:
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_free_shipping_loop', 5 );
function bbloomer_show_free_shipping_loop() {
echo '<p class="shop-badge">Orders over $99 ship FREE</p>';
}
And that's appearing correctly on the site.
However, I need a NEW message to appear that says "This product ships free" when a product is over $99. It needs to replace the "Orders over $99 ship FREE" that's there now if a product is over $99.
I think it's a simple function, but I can't find exactly what I need anywhere. Any help is appreciated!
Upvotes: 0
Views: 63
Reputation: 754
You should have access to the global $product
variable in the hook, so you can simply retrieve its price and conditionally show the text, e.g.:
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_free_shipping_loop', 5 );
function bbloomer_show_free_shipping_loop() {
global $product;
$product_price = $product->get_price();
if ( $product_price > 99 ) {
echo '<p class="shop-badge">This product ships free</p>';
} else {
echo '<p class="shop-badge">Orders over $99 ship FREE</p>';
}
}
Upvotes: 1