在WooCommerce中,使用以下代码在简单和变量产品中的产品价格之后添加自定义标签:
add_filter('woocommerce_variation_price_html','prices_custom_labels', 10, 2 );
add_filter('woocommerce_price_html','prices_custom_labels', 10, 2 );
function prices_custom_labels( $price, $product ){
// Set HERE your custom labels names
$per_dozen = ' '. __('per dozen', 'woocommerce' );
$per_case = ' '. __('per case (20 dozens)', 'woocommerce' );
// 1) Variable products
if ($product->product_type != 'simple' && $product->variation_id ) {
// Getting the array of existing attributes values for a variation
$variation_attribute_value = $product->variation_data;
// Here we keep only the last value in this array
$last_variation_attribute_slug_value = ' ' …Run Code Online (Sandbox Code Playgroud) 我有一个我无法解决的小问题.我有这个WooCommerce网站,其中包含可变产品,目前价格以这种方式显示:
每打$ 5.50 - 每打$ 100.00
我使用这个CSS规则,在每个价格之后添加"每打",但在当前场景中没有意义.
.price .amount:after {
content: " per dozen";
}
Run Code Online (Sandbox Code Playgroud)
我想用这种方式显示这个变量产品的价格:
每打 $ 5.50 - 每箱100.00 美元(数量)
在此先感谢您的帮助.