add_action( 'woocommerce_sale_flash', 'pancode_echo_sale_percent' );
/**
* Echo discount percent badge html.
*
* @param string $html Default sale html.
*
* @return string
*/
function pancode_echo_sale_percent( $html ) {
global $product;
/**
* @var WC_Product $product
*/
$regular_max = 0;
$sale_min = 0;
$discount = 0;
if ( 'variable' === $product->get_type() ) {
$prices = $product->get_variation_prices();
$regular_max = max( $prices['regular_price'] );
$sale_min = min( $prices['sale_price'] );
} else {
$regular_max = $product->get_regular_price();
$sale_min = $product->get_sale_price();
}
if ( ! $regular_max && $product instanceof WC_Product_Bundle ) {
$bndl_price_data = $product->get_bundle_price_data();
$regular_max = max( $bndl_price_data['regular_prices'] );
$sale_min = max( $bndl_price_data['prices'] );
}
if ( floatval( $regular_max ) ) {
$discount = round( 100 * ( $regular_max - $sale_min ) / $regular_max );
}
return '<span class="onsale">- ' . esc_html( $discount ) . '%</span>';
}
woocommerce_before_add_to_cart_button
поможет =ЕСЛИ(R[-1]<500;R[-1]C+1;1)
если у Вас в названиях столбцов числа, или =ЕСЛИ(A1<500;A1+1;1)
если в названиях столбцов буквы (внимание, в формуле в этом случае поправить букву столбца). Нажать Ctrl+Enteradd_action('woocommerce_before_add_to_cart_button', function(){
global $post;
$product = wc_get_product($post);
wc_display_product_attributes($product);
});
/**
* Get attachment image attributes.
*
* @param array $attr Image attributes.
* @return array
*/
function wc_get_attachment_image_attributes( $attr ) {
if ( isset( $attr['src'] ) && strstr( $attr['src'], 'woocommerce_uploads/' ) ) {
$attr['src'] = wc_placeholder_img_src();
if ( isset( $attr['srcset'] ) ) {
$attr['srcset'] = '';
}
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'wc_get_attachment_image_attributes' );