• Resolved Leonidas

    (@visionoptika)


    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

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Support Moshtafizur

    (@moshtafizur01)

    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,
    Moshtafizur

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @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.

    Thread Starter Leonidas

    (@visionoptika)

    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

    Plugin Author Algoritmika

    (@algoritmika)

    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 );
    Thread Starter Leonidas

    (@visionoptika)

    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

    Plugin Author Algoritmika

    (@algoritmika)

    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;
    }
    Thread Starter Leonidas

    (@visionoptika)

    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

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @visionoptika,

    Actually, you don’t need to change the snippet – it will work with the Pro version as well.

    Thread Starter Leonidas

    (@visionoptika)

    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

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @visionoptika,

    Oh, ok, I got it now. Let me check and get back to you about this.

    Plugin Author Algoritmika

    (@algoritmika)

    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.

    Thread Starter Leonidas

    (@visionoptika)

    Great, I will check and report back to you

    Best Leonidas

    Thread Starter Leonidas

    (@visionoptika)

    Hello

    everything works as expected. That’s why I bought the premium version too!

    Have a nice day

    Leonidas

    Plugin Support Moshtafizur

    (@moshtafizur01)

    Hi @visionoptika,

    We are happy to help 🙂

    Please consider leaving a review here if you liked the plugin/support.

    Kind regards,
    Moshtafizur

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Sales message at shop page’ is closed to new replies.