Skip to content

Instantly share code, notes, and snippets.

@tuongpgjz
Last active September 12, 2021 13:16
Show Gist options
  • Save tuongpgjz/2aaf5335089f680f17b8174fa5ff26be to your computer and use it in GitHub Desktop.
Save tuongpgjz/2aaf5335089f680f17b8174fa5ff26be to your computer and use it in GitHub Desktop.
woocommerce/loop/price.php
<?php
// Display lowest price of variant on product archives WooCommerce
// Format "Starting at %s per unit" - Exp: Starting at $4.5 per unit
// Put this file to folder /woocommerce/loop/ of your theme
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
$price_html = $product->get_price_html();
if ( $product->get_type() == 'variable' ) {
$min_price = $product->get_variation_price( 'min', true );
$price_html = sprintf(__('Starting at %s per unit'), wc_price( $min_price ));
}
if ( !empty( $price_html ) ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment