Custom Text After Price in WooCommerce Product- How To

Adding text after price in WooCommerce products using price filter. You can add logos after price in WooCommerce. Search for “woocommerce text after price”, customize WooCommerce price hook to add anything before/after product price field . Learn how to add text after price in WooCommerce. The price filter  woocommerce_get_price_htmlis default price hook. Used in themes […]

Adding text after price in WooCommerce products using price filter. You can add logos after price in WooCommerce. Search for “woocommerce text after price”, customize WooCommerce price hook to add anything before/after product price field . Learn how to add text after price in WooCommerce.

The price filter  woocommerce_get_price_htmlis default price hook. Used in themes for price display with customization of default display of price.

Add Text After Product Price:

It will affect all the products, relatively if you need to add text to specific products scroll below.

  • Price hook WooCommerce, can add text before and after the price in product.
  • You can change your own text above and below the line return $price.
  • Open your theme functions.php file, paste the below function to it.
    // first remove the filter to run new price filter.
    remove_filter( 'woocommerce_get_price_html', 'filter_woocommerce_get_price_html', 10, 2 ); 
    
    // rewrite woocommerce_get_price_html callback.
    function filter_woocommerce_get_price_html( $price, $instance ) { 
        echo " Before Price in all prodcuts. ";  
        
        return $price; 
        
        echo " After Price Text in all products. ";
    }; 
             
    // add the filter  again to override previous one
    add_filter( 'woocommerce_get_price_html', 'filter_woocommerce_get_price_html', 10, 2 );

Text After Specific Product Price:

In the below example we are adding some text after price for certain product. Pass multiple id of products you want to add text.

woocommerce_get_price_html

As seen custom text  in first and last product price after.

//WooCommerce text after price for certain products
 function tc_custom_price_filter( $price ) {
 global $post;
 $product_id = $post->ID;
 $my_product_array = array( 799,796,792 ); //hold product id's to add text
 if ( in_array( $product_id, $my_product_array )) {
 echo " your custom before text ";

 return $price;

 echo " your custom after text ";

 } else { return $price; } 
}
add_filter( 'woocommerce_get_price_html', 'tc_custom_price_filter' );

$my_product_array: holds the multiple id of published products. Add your own id’s for which text will be displayed.

In_Array : we match default products to intersect with our product array. For which the additional text will be displayed. Text will Added below and above return $price.

This change will occur in single product page and the listing of products. Having an issue consider commenting below.

Leave a Reply

Your email address will not be published. Required fields are marked *