如何解决Woocommerce按人均显示的最大变动价格
我有一个代码来显示woocommerce上每人的最高价。 我将数字4设置为最大人数,但现在我想将此值更改为变动价格数组长度。
Ex:该产品有3个价格,因此代码每3个划分一次。 该产品有5个价格,因此代码每5个细分。...
我想使它动态化,但是我不知道该怎么做。
add_filter( 'woocommerce_variable_price_html','bbloomer_variation_price_format',10,2 );
function bbloomer_variation_price_format( $price,$product ) {
// 1. Get min/max regular and sale variation prices
$min_var_reg_price = $product->get_variation_regular_price( 'min',true );
$min_var_sale_price = $product->get_variation_sale_price( 'min',true );
$max_var_reg_price = $product->get_variation_regular_price( 'max',true );
$max_var_sale_price = $product->get_variation_sale_price( 'max',true );
// 2. New $price,unless all variations have exact same prices
if ( ! ( $min_var_reg_price == $max_var_reg_price && $min_var_sale_price == $max_var_sale_price ) ) {
if ( $max_var_sale_price < $max_var_reg_price ) {
$price = sprintf( __( '<del>%1$s</del><ins>%2$s</ins>','woocommerce' ),wc_price( $max_var_reg_price/4 ),wc_price( $max_var_sale_price/4 ) );
} else {
$price = sprintf( __( '%1$s',wc_price( $max_var_reg_price/4 ) );
}
}
// 3. Return $price
return $price;
}
感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。