因此,我在商店中拥有的产品现在已经可以使用自定义html节省价格。 现在,我需要更改没有那些只有单一价格(正常价格)的属性的产品价格。
问题是它们具有相同的类,并且由于某些原因,当我更改html时,仅更改了was-now-save类,而具有正常价格的产品却没有更改。
add_filter( 'woocommerce_get_price_html','bbloomer_simple_product_price_format',10,2 );
function bbloomer_simple_product_price_format( $price,$product ) {
$str = "Ušteda:";
if ( $product->is_on_sale() && $product->is_type('simple') ) {
$price = sprintf( __( '<div class="was-now-save"><ul>
<li>
<div class="was">
<span class="text">MP cena:</span>%1$s</div>
</li><li><div class="save"><span class="text">' . $str . '</span>%3$s</div></li></li><div class="now"><span class="text">Cena:</span>%2$s</div></li></ul></div>','woocommerce' ),wc_price ( $product->get_regular_price() ),wc_price( $product->get_sale_price() ),wc_price( $product->get_regular_price() - $product->get_sale_price() ) );
}
return $price;
}