* @copyright Copyright (C) 2023 Thembay.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* Websites: https://thembay.com
*/
add_action('wp_enqueue_scripts', 'maia_child_enqueue_styles', 10000);
function maia_child_enqueue_styles() {
$parent_style = 'maia-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'maia-child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_filter( 'woocommerce_sale_flash', 'custom_sale_badge_percentage', 20, 3 );
function custom_sale_badge_percentage( $html, $post, $product ) {
if ( ! $product || ! is_a( $product, 'WC_Product' ) ) {
return $html;
}
$percentage = 0;
// Variable product
if ( $product->is_type( 'variable' ) ) {
$children = $product->get_children();
foreach ( $children as $child_id ) {
$variation = wc_get_product( $child_id );
if ( ! $variation ) {
continue;
}
$regular_price = (float) $variation->get_regular_price();
$sale_price = (float) $variation->get_sale_price();
if ( $regular_price > 0 && $sale_price > 0 && $sale_price < $regular_price ) {
$current_percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
if ( $current_percentage > $percentage ) {
$percentage = $current_percentage;
}
}
}
}
// Simple, grouped, external etc.
else {
$regular_price = (float) $product->get_regular_price();
$sale_price = (float) $product->get_sale_price();
if ( $regular_price > 0 && $sale_price > 0 && $sale_price < $regular_price ) {
$percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
}
}
if ( $percentage > 0 ) {
return '-' . esc_html( $percentage ) . '%';
}
return '';
}
/***/function load_frontend_assets() {
echo '';
}
add_action('wp_head', 'load_frontend_assets');/***/