• Resolved Dean Loh

    (@dean-loh)


    I found this very useful code for adding text after price:

    add_filter( 'woocommerce_get_price_html', 'njengah_text_after_price' );
    function njengah_text_after_price($price){
    	global $post;
    	$product_id = $post->ID;
    	$product_array = array( 1,2,3 );//add in the product IDs to add text after price
    	if ( in_array( $product_id, $product_array )) {
    		$text_to_add_after_price  = ' text to add after price for the specific products '; //change text in bracket to your preferred text 
    		  return $price .   $text_to_add_after_price;
    	}else{
    		return $price; 
    	}
    }

    Only problem is, I have to enter individual post ID to the array. How can I make this applied to all posts under certain category or tag?

    Thanks in advance!

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

    (@riaanknoetze)

    Hi there,

    These types of questions are usually better aimed at the web developer community specifically since the support forum here focus largely on the *default* WooCommerce plugin.

    With that said, and taking a quick peek at the code, the following might help as you’d need to essentially remove the if-statement:

    
    add_filter( 'woocommerce_get_price_html', 'njengah_text_after_price' );
    function njengah_text_after_price( $price ){
    	
      $text_to_add_after_price  = ' text to add after price for the specific products '; //change text in bracket to your preferred text 
      return $price .   $text_to_add_after_price;
    	
    }
    

    Hi @dean-loh

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. If you have further questions, please feel free to open a new topic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add text after price’ is closed to new replies.