Replace WooCommerce variable products price range with 'Up to' and the max price

前端 未结 2 1828
误落风尘
误落风尘 2020-12-07 05:10

I found the following code (from here) which enables me to show on a variable price product on WooCommerce: \'From: £10\' (on a £10 - £50 product). I would

2条回答
  •  盖世英雄少女心
    2020-12-07 06:01

    Add this

        add_filter( 'woocommerce_variable_sale_price_html', 
       'lw_variable_product_price', 10, 2 );
        add_filter( 'woocommerce_variable_price_html', 
        'lw_variable_product_price', 10, 2 );
    
         function lw_variable_product_price( $v_price, $v_product ) {
    
        // Product Price
         $prod_prices = array( $v_product->get_variation_price( 'min', true ), 
         $v_product->get_variation_price( 'max', true ) );
        $prod_price = $prod_prices[0]!==$prod_prices[1] ? sprintf(__('Up to: %1$s', 
     'woocommerce'), 
       wc_price( $prod_prices[0] ) ) : wc_price( $prod_prices[0] );
    
      // Regular Price
      $regular_prices = array( $v_product->get_variation_regular_price( 'min', true ), 
      $v_product->get_variation_regular_price( 'max', true ) );
      sort( $regular_prices );
       $regular_price = $regular_prices[0]!==$regular_prices[1] ? sprintf(__('Up to: 
      %1$s','woocommerce')
      , wc_price( $regular_prices[0] ) ) : wc_price( $regular_prices[0] );
    
        if ( $prod_price !== $regular_price ) {
       $prod_price = ''.$regular_price.$v_product->get_price_suffix() . ' 
        ' . 
        $prod_price . $v_product->get_price_suffix() . '';
        }
       return $prod_price;
       }
    

提交回复
热议问题