Last active
September 12, 2021 13:16
-
-
Save tuongpgjz/2aaf5335089f680f17b8174fa5ff26be to your computer and use it in GitHub Desktop.
woocommerce/loop/price.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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