Skip to content

Instantly share code, notes, and snippets.

@luizbills
Last active April 28, 2021 13:18
Show Gist options
  • Save luizbills/cd5d1ef1dd93150470005593561c7197 to your computer and use it in GitHub Desktop.
Save luizbills/cd5d1ef1dd93150470005593561c7197 to your computer and use it in GitHub Desktop.
Mostrar preço dos produtos variáveis com "apartir de"
<?php
/**
* @version 2.0.0
* @author Luiz Paulo Bills <[email protected]>
*/
add_filter( 'woocommerce_variable_sale_price_html', 'lpb_wc_variable_product_price_html', 10, 2 );
add_filter( 'woocommerce_variable_price_html','lpb_wc_variable_product_price_html', 10, 2 );
function lpb_wc_variable_product_price_html ( $html, $product ) {
$min_price = $product->get_variation_regular_price( 'min', true );
$max_price = $product->get_variation_regular_price( 'max', true );
if ( ! empty( $min_price ) && $min_price !== $max_price ) {
if ( $product->is_on_sale() ) {
$sale_price = $product->get_variation_sale_price( 'min', true );
$html = '<del>' . wc_price( $min_price ) . '</del><ins>' . wc_price( $sale_price ) . '</ins>';
} else {
$html = '<ins>' . wc_price( $min_price ) . '</ins>';
}
return '<span class="from-text">' . esc_html__( 'A partir de', 'woocommerce' ) . '&nbsp;</span>' . $html;
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment