• Resolved Make carlos

    (@make-carlos)


    Hi Support team.
    In shop page/Archive page. I need to show Varibale product price instead of Select options so i have used this filter:

    add_filter( 'woocommerce_variable_price_html', 'custom_variable_displayed_price', 10, 2 );
    function custom_variable_displayed_price( $price, $product ) {
        // Only for archives pages
        if ( ! ( is_shop() || is_product_category() || is_product_tag() || is_front_page() ) )
            return $price_html;
    
        $prices = $product->get_variation_prices( true );
        $min_price = current( $prices['price'] );
        $max_price = end( $prices['price'] );
    
        $min_price_html = $product->get_price_suffix().wc_price( $min_price );
        $price = sprintf( __( '%1$s', 'woocommerce' ), $min_price_html );
    
        echo $price;
    }

    This code only works if i use Echo $price at the end of function and if i use return $price its not working. as per standard it should be return $price but as of now i have used echo.

    but i am facing issues when i do search using your plugin then in search result page. All prices for are printing on top of page like this:

    £4595.00£100.00£200.00£130.00£87.00£69.00£85.00£4595.00£4595.00£4595.00£4595.00£4595.00 something like this.

    could you please check this with your plugin.

    Thanks
    Make

Viewing 1 replies (of 1 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hi,

    Well you need to use return instead of echo in this function because it can break other things that also use this filter.

    So if you need this variations price to be visible on shop and archive pages that modify your code snippet to

    add_filter( 'woocommerce_variable_price_html', 'custom_variable_displayed_price', 999, 2 );
    function custom_variable_displayed_price( $price, $product ) {
        // Only for archives pages
        if ( is_front_page() )
            return $price;
    
        $prices = $product->get_variation_prices( true );
        $min_price = current( $prices['price'] );
        $max_price = end( $prices['price'] );
    
        $min_price_html = $product->get_price_suffix().wc_price( $min_price );
        $price = sprintf( __( '%1$s', 'woocommerce' ), $min_price_html );
    
        return $price;
    }

    Regards

Viewing 1 replies (of 1 total)
  • The topic ‘Could you please check this ?’ is closed to new replies.