The question is about the variable product! For a simple product, it becomes the following code:

add_action( 'woocommerce_before_shop_loop_item_title', function() { global $product; $akc = get_post_meta(get_the_ID(), '_sale_price', true); if ( $akc > 0 ) { echo '<span class="onsale soldout">Акция!</span>'; } }); 

But it is not clear how to get the value of all the fields with the sale price (sale_price) for variations? Tried to take from $ prices_array , but in vain.

UPDATE

Get the price in this way also did not work:

 if ( 'product_variation' === $_this->post_type ) { $data = (object) $_this->get_data(); $variation_price = $data->price; $product_id = $data->parent_id; $variation_sale_price = get_sale_price( $variation_price, $product_id ); var_dump($variation_sale_price); 

    1 answer 1

    Could get a minimum price of variation, but how to select exactly 'sale_price' ?

     add_action( 'woocommerce_before_shop_loop_item_title', function($price) { global $product; if($product->product_type == 'variable') { $prices = array( $product->get_variation_sale_price( 'min', true ) ); if ( !empty ($prices) ) { echo '<span class="onsale soldout">Акция!</span>'; } }}); 

    UPDATE

    The question is closed, figured out, was it really difficult to tell an inexperienced fool what to do?)

     add_action( 'woocommerce_before_shop_loop_item_title', function($price) { global $product; if($product->product_type == 'variable') { $prices = array( $product->get_variation_sale_price( 'min', true )); $prices2 = array( $product->get_variation_regular_price( 'min', true )); if ($prices !== $prices2){ echo '<span class="onsale soldout">Акция!</span>'; } }}); 
    • No offense. People don't always have time to answer questions. Here is not paid support service with a rigidly defined response time. - KAGG Design
    • Yes, I understand, no offense, especially in relation to you, only thanks to you) - user271244