Add html after price | WordPress.org

[ad_1]

I just altered the woocommerce price html to show the price per unit (add html on the end of the price html).

When pricing rules are active (graduated discount) the price html gets overwritten / the price per unit disappears. How to add this to the end of the price string when pricing rules are active? Below is the code I used

function dd_change_product_html( $price_html, $product ) {
	if($product->price > 0){
		 $bundelditems = $product->get_nbbundleditems();
		 if($bundelditems != null){
			 $perunit = $product->price / $bundelditems;
			 $price_html .= '<p class="unitprice"><span>'.number_format($perunit, 2, ',', '').' p/st</span></p>';
		 }
 	}
 	return $price_html;
}
add_filter( 'woocommerce_get_price_html', 'dd_change_product_html', 10, 2 );

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer