1

我正在 woocommerce 上建立一家商店,我有多种产品,每种产品都有其独特的价格。我想要做的是始终显示最低价格,即使没有选择任何选项。当稍后选择选项时,这个价格应该会改变(就像选项之后底部的那个,但总是显示)。

它是在选项之后还是之前显示并不重要。

我尝试使用这个:

add_filter( 'woocommerce_show_variation_price', '__return_true' );

但它不适用于最新版本的 woocommerce。谢谢你的帮助。

4

2 回答 2

1

要显示最低价格,请使用以下命令:

add_filter( 'woocommerce_variable_sale_price_html', 'custom_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_variation_price_format', 10, 2 );

function custom_variation_price_format( $price, $product ) {

    // Main Price
    $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
    $price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    // Sale Price
    $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
    sort( $prices );
    $saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    if ( $price !== $saleprice ) {
        $price = '<del>' . $saleprice . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>';
    }
    return $price;
}
于 2019-12-03T13:18:43.910 回答
1

请使用以下功能:

add_filter( 'woocommerce_format_sale_price', 'addweb_solu_sale_price', 20, 3 );
function addweb_solu_sale_price( $price, $regular_price, $sale_price ) {
    return wc_price( $sale_price );
}
于 2019-12-03T13:31:17.610 回答