• Resolved chris15326

    (@chris15326)


    Hey! So I managed to add some php code in order to show a price suffix.

    Now I would want to only show this at the product page.

    So that restriction would need to be added to this code:

    add_filter( 'woocommerce_get_price_suffix', 'bbloomer_add_price_suffix_price_inc_tax', 99, 4 );
       
    function bbloomer_add_price_suffix_price_inc_tax( $suffix, $product, $price, $qty ){
        $suffix = ' <small>(inkl. MwSt.)</small>';
        return $suffix;
    }

    Hope you can help me out on this one again!

    With kind regards
    Chris

    • This topic was modified 2 years ago by chris15326.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @chris15326

    Thanks for reaching out!

    I understand that you want to display the price suffix on your single product page only.

    I found the thread below similar to your use case here:

    https://stackoverflow.com/questions/67969861/add-price-suffix-only-on-woocommerce-single-product-page-without-linked-products

    Tested this on my site and it is working on my end:

    Shop page:

    Image Link: https://snipboard.io/LrwsDQ.jpg

    Single Products Page:

    Image Link: https://snipboard.io/BNKAU4.jpg

    Hope this helps!

    Thread Starter chris15326

    (@chris15326)

    Thanks for your time and effort! And yes!

    This code:

    function filter_woocommerce_get_price_html( $price, $product ) {
        global $woocommerce_loop;
    
        if ( is_product() && $woocommerce_loop['name'] !== 'related' && $woocommerce_loop['name'] !== 'up-sells' ) {
            $price .= ' <small> incl. tax</small>';
        }
        
        //return $price;
        return apply_filters( 'woocommerce_get_price', $price );
    }
    add_filter( 'woocommerce_get_price_html', 'filter_woocommerce_get_price_html', 10, 2 );

    Seems to work exept in this location:
    https://i.postimg.cc/hPHBSGFx/megamenu.jpg

    it still shows up on itmes displayed through the mega menu. Anywhere else its fine now.

    Wonder if somebody of your wizards can take a look at that and see if he or she can exclude it from there as well.

    Again, thank you so much for your support! You have no idea how much appreciate your help!

    With kind regards
    Chris

    Hi @chris15326

    it still shows up on itmes displayed through the mega menu. Anywhere else its fine now.

    I’m glad you were able to help you! ??

    Wonder if somebody of your wizards can take a look at that and see if he or she can exclude it from there as well.

    This is a custom code that is outside our scope of support, I am leaving this thread open for a bit to see if anyone can chime in to help you out.

    For questions related to development and custom coding, your best bet is to ask on any of these channels for support. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, too.

    WooCommerce Developer Resources Portal
    WooCommerce Advanced Facebook group
    WooCommerce Community Forum
    WooCommerce Developer Slack Channel.
    – Hire a WooCommerce Expert

    Hope this helps!

    Thread Starter chris15326

    (@chris15326)

    Finally I found the solution that works perfect!

    For anybody that wants to do the same and stumbles uppon this thread in future:

    function custom_price_suffix( $price, $product ) {
        global $woocommerce_loop;
    
        if( is_product() && !$woocommerce_loop['name'] == 'related' ) {
            $price = $price . ' <span class="make-me-small"> Inclusive of all taxes</span>';
        }
        //return $price;
        return apply_filters( 'woocommerce_get_price', $price );
    }
    add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding a price suffix ONLY on product pages’ is closed to new replies.