$gallery = get_field('gallery'); ?>
ОБРАЗ В ДЕТАЛЯХ
$products = get_field('products'); ?>
foreach($products as $item){
$post = $item->ID;
setup_postdata($post);
$product = wc_get_product( $post ); ?>
} wp_reset_postdata(); ?>
woocommerce_template_single_add_to_cart() ?>
if ( $product->is_on_sale() ) {
$percentage = '';
if ( $product->get_type() == 'variable' ) {
$available_variations = $product->get_variation_prices();
$max_percentage = 0;
foreach( $available_variations['regular_price'] as $key => $regular_price ) {
$sale_price = $available_variations['sale_price'][$key];
if ( $sale_price < $regular_price ) {
$percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
if ( $percentage > $max_percentage ) {
$max_percentage = $percentage;
}
}
}
$percentage = $max_percentage;
} elseif ( ( $product->get_type() == 'simple' || $product->get_type() == 'external' || $product->get_type() == 'variation' ) ) {
$percentage = round( ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100 );
}
if ( $percentage ) {
echo '-' . $percentage . '%' . '';
}else{
echo '' . esc_html__( 'Sale', 'woodmart' ) . '';
}
} ?>
woocommerce_template_single_price() ?>