Customize WooCommerce Variation Text

Intermediate

PHP

Details

This code snippet for WooCommerce or Divi BodyCommerce allows you to customize the text for your variable products as they are displayed in the product loop. This code should be added to the functions.php file of your child theme and can be customized to display formats like “From…”, “Starting at..”, etc instead of the default min to max pricing format.

Snippets Demo

Example of custom text for variable products in WooCommerce and Divi BodyCommerce

Code

1

Description:
This code will give you the framework to customize the way that variation pricing is displayed in the product loop.

Language: PHP

Where to add: functions.php

                        add_filter('woocommerce_variable_sale_price_html', 'custom_variation_price_format', 10, 2);
add_filter('woocommerce_variable_price_html', 'custom_variation_price_format', 10, 2);

function custom_variation_price_format($price, $product) {
    // Get all variation prices
    $prices = $product->get_variation_prices(true);

    // Get the minimum and maximum price
    $min_price = current($prices['price']);
    $max_price = end($prices['price']);

    // Set your custom price format
    if ($min_price == $max_price) {
        $price = wc_price($min_price); // Single price
    } else {
        // Custom price formats
        $price = sprintf(__('From %1$s', 'woocommerce'), wc_price($min_price)); // Example: "From $50"
        // $price = sprintf(__('%1$s+', 'woocommerce'), wc_price($min_price)); // Example: "$50+"
        // $price = sprintf(__('Starting at %1$s', 'woocommerce'), wc_price($min_price)); // Example: "Starting at $50"
    }

    return $price;
}

                    

Related Snippets

Explore more from Divi Engine

Divi Form Builder

Divi Form Builder

From simple contact forms to complex frontend post or product creation, Divi Form Builder has you covered.

Divi Form Builder
Find out more
Divi Machine

Divi Machine

Build complex websites that displays dynamic fields you can filter, search and so much more with the Divi Builder.

Divi Machine
Find out more
Divi BodyCommerce

Divi BodyCommerce

A versatile toolkit for developers using Divi and WooCommerce together, designed to boost your e-commerce site and achieve greater conversion rates.

Divi BodyCommerce
Find out more
Divi Loop Extender

Divi Loop Extender

Unlock the Full Power of Divi 5 Loop Builder Add advanced sorting, filtering, and relationship logic right inside the Visual Builder.

Divi Loop Extender
Find out more
Divi Membership

Divi Membership

Monetize your Divi websites by transforming them into membership sites with seamless subscription management, user-friendly interfaces, and customizable membership tiers.

Divi Membership
Find out more
Divi Machine Accounts

Divi Machine Accounts

Build an account area for your customers to edit their details, access wishlist, submitted posts and more. *Note: Requires Divi Machine installed and active

Divi Machine Accounts
Find out more
Divi Ajax Filter

Divi Ajax Filter

Filter WooCommerce, Posts & Custom Posts without reloading the page.

Divi Ajax Filter
Find out more
Divi Mobile

Divi Mobile

Divi Mobile helps you create beautiful looking mobile menus without having to code.

Divi Mobile
Find out more
Divi Nitro

Divi Nitro

Give your Divi website that extra boost of speed with our Divi Nitro plugin to enhance your customer's experience.

Divi Nitro
Find out more
Divi Protect

Divi Protect

Password protect the content of your Divi website with our Divi Protect plugin. Keep unwanted eyes out!

Divi Protect
Find out more
Divi Mega Menu

Divi Mega Menu

Improve the user experience of your Divi website with our Divi Mega Menu plugin by creating dynamic menus using the Divi Builder.

Divi Mega Menu
Find out more