Home Forums WoodMart support forum Price range (variable products)

Price range (variable products)

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #625018

    john_charalambidis
    Participant

    Hie.

    We have set a new store, there are many variable products with wide range of prices depending on the sizes, we would like to have the option to apply to all variable products a name “From-To” e.g (Room Divider – A breath of summer “From 192,19 € To: 362,07 €” .
    The template itself have the option to show the range of prices, but without mentioning “From-To” there are misunderstandings.

    Thanks in advance.

    #625021

    john_charalambidis
    Participant

    For the time being, we have set ( “Hide “to” price) for Variable products, to avoid issues with costumers, since they thought it was wrong price input.

    I will add the Screenshots–>

    Attachments:
    You must be logged in to view attached files.
    #625135

    Hello,

    To add “From-To” before the price range on variable products, you can use the following custom code in your child theme’s functions.php file:

    add_filter('woocommerce_variable_price_html', 'custom_variable_price_format', 10, 2);
    function custom_variable_price_format($price, $product) {
        $min_price = wc_get_price_to_display($product, ['price' => $product->get_variation_price('min')]);
        $max_price = wc_get_price_to_display($product, ['price' => $product->get_variation_price('max')]);
        $price = sprintf(__('From %s To %s', 'woocommerce'), wc_price($min_price), wc_price($max_price));
        return $price;
    }

    This will display the price range in the “From-To” format for all variable products.

    Best Regards

    #625201

    john_charalambidis
    Participant

    Thanks for your support.
    It worked perfect !! , but we prefer instead of showing from – to, showing only the starting price “From”. We have few products that belong to variable products with same price range and it looks a mess, and sounds like a better marketing idea.

    Could you please reproduce the code with these characteristics only “From” ?
    Thanks in advance.

    #625240

    Hello,

    You can use the following custom code in your child theme’s functions.php file:

    add_filter('woocommerce_variable_price_html', 'custom_variable_price_from', 10, 2);
    function custom_variable_price_from($price, $product) {
        $min_price = wc_get_price_to_display($product, ['price' => $product->get_variation_price('min')]);
        $price = sprintf(__('From %s', 'woocommerce'), wc_price($min_price));
        return $price;
    }

    Best Regards

Viewing 5 posts - 1 through 5 (of 5 total)