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.
Customize WooCommerce Variation Text
Details
Snippets Demo
Code
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
Easy | CSS
Make Your Divi Ajax Filter Sticky on Mobile Devices
Feb 21 2024
Explore more from Divi Engine
Divi Membership
Monetize your Divi websites by transforming them into membership sites with seamless subscription management, user-friendly interfaces, and customizable membership tiers.
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 Form Builder
From simple contact forms to complex frontend post or product creation, Divi Form Builder has you covered.
Divi Ajax Filter
Filter WooCommerce, Posts & Custom Posts without reloading the page.
Divi Machine
Build complex websites that displays dynamic fields you can filter, search and so much more with the Divi Builder.
Divi Mobile
Divi Mobile helps you create beautiful looking mobile menus without having to code.
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 Nitro
Give your Divi website that extra boost of speed with our Divi Nitro plugin to enhance your customer's experience.
Divi Protect
Password protect the content of your Divi website with our Divi Protect plugin. Keep unwanted eyes out!
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.