Sales message at shop page
-
Hello,
do you think it’s possible to display a message into the shop or the product page regarding the type of discount we have?
Like this example https://prnt.sc/GT-aofdHZghd
Regards
Leonidas
-
Hi @visionoptika,
Thanks for reaching out.
At this moment, it is not possible to display a message with the plugin’s existing settings. But I have passed your request on to the relevant team. They will get back to you as soon as they can.
Kind regards,
MoshtafizurHi, @visionoptika,
I’m not sure if I got the question correctly, but I think you can achieve that with this PHP snippet:
add_action( 'woocommerce_after_shop_loop_item', function () { global $product; if ( ! $product->is_on_sale() ) { return; } echo '<p>' . esc_html__( 'Message for the shop pages.' ) . '</p>'; }, 11 ); add_action( 'woocommerce_single_product_summary', function () { global $product; if ( ! $product->is_on_sale() ) { return; } echo '<p>' . esc_html__( 'Message for the single product pages.' ) . '</p>'; }, 31 );
The snippet will add your custom message to all on-sale products. It will be displayed on the shop and single product pages (right after the add-to-cart button).
Please give it a try and let me know what you think.
Hello
I am familiar with this code but it displays the message to all products.
What I have is mind is about a new field inside the discount group where we will be able to add our message and display it only to those products that meet the requirements of this group.
Hope I made myself clear this time
Regards
Leonidas
Hi, @visionoptika,
Do you mean to display the message only for products discounted by our plugin, i.e., not for all on-sale products? If that’s the case, please update the snippet to:
add_action( 'woocommerce_after_shop_loop_item', function () { global $product; if ( ! function_exists( 'alg_wc_global_shop_discount' ) || ! alg_wc_global_shop_discount()->core->is_gsd_product( $product ) ) { return; } echo '<p>' . esc_html__( 'Message for the shop pages.' ) . '</p>'; }, 11 ); add_action( 'woocommerce_single_product_summary', function () { global $product; if ( ! function_exists( 'alg_wc_global_shop_discount' ) || ! alg_wc_global_shop_discount()->core->is_gsd_product( $product ) ) { return; } echo '<p>' . esc_html__( 'Message for the single product pages.' ) . '</p>'; }, 31 );
Hello
this is what I am looking for and it’s working great. Only one last thing. Is there a way to style the message?
Regards
Leonidas
Sure. Add a class to the element by replacing
<p>
with<p class="my-gsd-product">
in our snippet. Then add something like this to your custom CSS:.my-gsd-product { border: 1px dashed #DEDEDE; background: #F7F7F7; padding: 5px; margin: 5px; color: black; }
Perfect.
I want to ask something else for last. I am planning to buy the premium version because I want to be able to add more than one discount group. I am wondering if it is possible to change the previous snippet and make it work with the premium version too.
Regards
Leonidas
Hi, @visionoptika,
Actually, you don’t need to change the snippet – it will work with the Pro version as well.
Hello
what I have in my mind is something different.
Let’s say I run two different group discounts simultaneously.
So If I want to display two different messages (one for every group discount) then I suppose I will need to write the previous snippet twice.
What I don’t understand is how I will target the right message for every discount?
Is this possible?
Regards
Leonidas
Hi, @visionoptika,
Oh, ok, I got it now. Let me check and get back to you about this.
Hi, @visionoptika,
Since the plugin v1.9.2, you can display different messages for different discount groups like this:
add_action( 'woocommerce_after_shop_loop_item', function () { global $product; if ( ! function_exists( 'alg_wc_gsd_get_product_discount_groups' ) ) { return; } $groups = alg_wc_gsd_get_product_discount_groups( $product ); if ( empty( $groups ) ) { return; } $group = $groups[0]; /** * Set your messages here, in "group num => message" format. */ $messages = array( 1 => esc_html__( 'Message for the first discount group.' ), 2 => esc_html__( 'Message for the second discount group.' ), 3 => esc_html__( 'Message for the third discount group.' ), ); if ( isset( $messages[ $group ] ) ) { echo '<p class="my-gsd-product">' . $messages[ $group ] . '</p>'; } }, 11 );
Please give it a try and let me know what you think.
Great, I will check and report back to you
Best Leonidas
Hello
everything works as expected. That’s why I bought the premium version too!
Have a nice day
Leonidas
Hi @visionoptika,
We are happy to help 🙂
Please consider leaving a review here if you liked the plugin/support.
Kind regards,
Moshtafizur
- The topic ‘Sales message at shop page’ is closed to new replies.