Support » Plugins » Woocommerce: Address one particular category in functions.php

  • Resolved lapasta

    (@lapasta)


    Dear gents,

    I’m almost ready with my own online shop, but currently struggling with some little problems.

    I would like to add a little string above the “put-into-cart”-button to give customers a short information.
    After some hours of surching and testing I found this code, which works very well:

    function customerinfo() {
    echo '(This product is 0.5 m long.)';
    }
    add_action( 'woocommerce_before_add_to_cart_button', 'customerinfo' );

    However, I would like to add this string only for one category, but not for all categories. Therefore, I tried to use:

    function customerinfo() {
    echo '(This product is 0.5 m long.)';
    }
    if ( is_product_category() ) {
    if ( is_product_category('fabric') ) {
    add_action( 'woocommerce_before_add_to_cart_button', 'customerinfo' );
    }

    Anyhow, it doesn’t work. What’s my thinking failure?
    Many thanks for any help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter lapasta

    (@lapasta)

    Hi,
    could finaly resolve my problem by switching terms.
    Maybe there is anybody with the same problem.
    Best wishes!

    add_action( 'woocommerce_before_add_to_cart_button', 'bezug' );
    function customerinfo() {
    	if ( has_term ( 'fabric', 'product_cat') ) {
     	echo 'his product is 0.5 m long.';
    	}
    	else {
      	echo 'something else';
    }
    }
    Thread Starter lapasta

    (@lapasta)

    topic resolved

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Woocommerce: Address one particular category in functions.php’ is closed to new replies.