小编DVJ*_*VJy的帖子

显示 Woocommerce 3 上的默认变化价格和节省金额

我需要在我的Woocommerce 主页和类别页面上显示默认变化价格、常规价格和节省金额

我在此链接答案中找到了以下代码 在 WooCommerce 中显示最低变化价格和折扣百分比

add_filter( 'woocommerce_get_price_html', 'custom_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_price_format', 10, 2 );
function custom_price_format( $price, $product ) {

    // Main Price
    $regular_price = $product->is_type('variable') ? $product->get_variation_regular_price( 'min', true ) : $product->get_regular_price();
    $sale_price = $product->is_type('variable') ? $product->get_variation_sale_price( 'min', true ) : $product->get_sale_price();


    if ( $regular_price !== $sale_price && $product->is_on_sale()) {
    // Percentage calculation and text
    $percentage = round( ( $regular_price - $sale_price ) / $regular_price * 100 ).'%';
    $percentage_txt = __(' Save', 'woocommerce' ).' …
Run Code Online (Sandbox Code Playgroud)

php product woocommerce price product-variations

5
推荐指数
1
解决办法
5083
查看次数

标签 统计

php ×1

price ×1

product ×1

product-variations ×1

woocommerce ×1