Are you a Digital Agency? 📣 Let's get to know each other!

ResourcesWordpressMostrare i prezzi delle varianti in WooCommerce con il formato “Da XX€”

Mostrare i prezzi delle varianti in WooCommerce con il formato “Da XX€”

In the world of e-commerce, the way you present the price of a product can make the difference between a purchase and an abandonment. One of the most effective ways to make it more attractive is to use the "From XX€" format to display the prices of product variants in WooCommerce. In this article, I will guide you step by step on how to insert a code snippet to achieve this.

Step 1: Preparation

Before you start, make sure you have installed and activated the WooCommerce plugin on your website. In addition, you should have a good knowledge of the basic functionality of WooCommerce and the management of products and variants.

Step 2: Create a function file

To insert the code snippet, you need to create a custom function file in your WordPress theme. To do this, open the theme editor and create a new file called functions.php in the folder wp-content/themes/your-theme.

I recommend you do this in your 'Child' theme folder so that you do not lose these changes when you go to update your theme.

Step 3: Insert the code snippet

In the file functions.php, add the following code:

/**
 * Snippet Name:	WooCommerce Show Coupon Code Used In Emails
 * Snippet Author:	halkoo.com
 */

add_filter( 'woocommerce_get_price_html', 'change_variable_products_price_display', 10, 2 );

function change_variable_products_price_display( $price, $product ) {
    // Only for variable products type
    if( ! $product->is_type('variable') ) return $price;
    $prices = $product->get_variation_prices( true );
    if ( empty( $prices['price'] ) )
        return apply_filters( 'woocommerce_variable_empty_price_html', '', $product );
    $min_price = current( $prices['price'] );
    $max_price = end( $prices['price'] );
    $prefix_html = '<span class="price-prefix">' . __('Da ') . '</span>';
    $prefix = $min_price !== $max_price ? $prefix_html : ''; // HERE the prefix
    return apply_filters( 'woocommerce_variable_price_html', $prefix . wc_price( $min_price ) . $product->get_price_suffix(), $product );
}

Save the file.

After following these steps, the prices of WooCommerce product variants on your website should be displayed in the format 'From XX€'.

In this way, you can make your website more attractive and increase the chances of conversion for your customers. Happy sales!

Need help? Write to info@halkoo.com to receive a customised quote for your new website or e-commerce shop.