• Resolved lkafrazier

    (@lkafrazier)


    I have some code running globally on my website that places a notation between my product variation and the add to cart button, however, I do not want it to appear globally, but rather only applied to particular Product Category Slugs or Product ID’s.

    I’ve tried what seems like a million different things to make it happen, but the code still appears on every product/category I have published.

    The code is as follows:

    add_action( ‘woocommerce_before_add_to_cart_button’ , ‘aj_add_below_prod_var’, 5 );

    function aj_add_below_prod_var() { echo ‘ Quantities are in HALF YARD increments. (1=1/2 Yard, 2=1 Yard, 3=1 1/2 Yards, etc.) ‘; }

    Can anyone help? I only want it to appear on the products that are in the category slug ‘pre-order-fabrics’

    Thanks so much for any assistance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi there,

    You can try this:

    function aj_add_below_prod_var() { 
    if( has_term( array( 'pre-order-fabrics' ) )) {
    echo 'Quantities are in HALF YARD increments. (1=1/2 Yard, 2=1 Yard, 3=1 1/2 Yards, etc.) ';
    }
    }

    Please note that we provide no warranty or support for custom code or 3rd party plugins (meaning we cannot not help you further with this code snippet or www.remarpro.com / GitHub plugins). Use them at your own risk.

    **Also: Before you do that, please do make a full backup!**

    Kind regards,

    Thread Starter lkafrazier

    (@lkafrazier)

    Thank you very much for your time and reply! I’ll do a backup and try this out!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hook that specifies an action code is only applied to a certain product category’ is closed to new replies.