【问题标题】:WooCommerce - Show Regular and Sale Price for The Product Variation which has Flat PriceWooCommerce - 显示具有固定价格的产品变体的常规价格和销售价格
【发布时间】:2020-08-21 01:34:09
【问题描述】:

场景是Simple product,Variable product是woocommerce的两种不同的产品类型。

  • 简单的产品会显示正常价格和销售价格。
  • 变化会给您一个价格范围。

我想要实现的是,有些产品有 50 多种变体,它们有不同的销售价格和正常价格。该产品的价格范围是票价。

但也有一些产品的变体具有相同的常规价格和销售价格。价格没有区别。我希望价格显示为


我同意出现的问题是我为什么不应该选择简单的产品?因为在简单的产品中,我不允许添加下拉菜单中可用的颜色。请问有什么建议吗?

【问题讨论】:

  • 您的图片/网址似乎不起作用?
  • ibb.co/tBq635V请查看链接

标签: wordpress woocommerce hook-woocommerce price


【解决方案1】:

我正在寻找解决 codeNinja sn-p 问题的确切钩子!这就是它的固定方式:

function wc_ninja_custom_variable_price( $price, $product ) {
    // Main Price
    $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
    $price = $prices[0] !== $prices[1] ? sprintf( __( 'Starting 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( __( '', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );

    if ( $price !== $saleprice ) {
        $price = ' <ins class="highlight"> '. $price.' </ins> <del class="strike"> '.$saleprice .' </del> ';
    }

    return $price;
}
add_filter( 'woocommerce_variable_sale_price_html', 'wc_ninja_custom_variable_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_ninja_custom_variable_price', 10, 2 );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    相关资源
    最近更新 更多