小编Pet*_*oro的帖子

替换价格范围处理Woocommerce 3中的默认变化显示价格

在我们的woocommerce网站上,我试图根据客户从下拉菜单中选择的变化来更新显示的价格,如下所示:

下拉变化选择示例

我使用了LoictheAztec在另一个答案中提交的php函数:
用WooCommerce 3中的选定变动价格替换可变价格范围

add_action( 'woocommerce_before_single_product', 'move_variations_single_price', 1 );
function move_variations_single_price(){
    global $product, $post;

    if ( $product->is_type( 'variable' ) ) {
        // removing the variations price for variable products
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

        // Change location and inserting back the variations price
        add_action( 'woocommerce_single_product_summary', 'replace_variation_single_price', 10 );
    }
}

function replace_variation_single_price(){
    global $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' …
Run Code Online (Sandbox Code Playgroud)

php wordpress variations woocommerce price

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

标签 统计

php ×1

price ×1

variations ×1

woocommerce ×1

wordpress ×1