how to add Hot attribute like sale on product image in Woocommerce

i want a hot sticker on product image, same like as SALE.
so i added a function for adding checkbox in add product page below the SALE Price. and its working fine, now i want if admin checked the Hot product checkbox so the sticker should be show on the product image. i have a css class ‘hot-product’. how can i add this class on product image if admin checked the Hot Product checkbox

here is my function for adding checkbox below the sale price.

/ Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_field' );

// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );


function woo_add_custom_general_field() {

 global $woocommerce, $post;

 echo '<div class="options_group">';

 // Checkbox
 woocommerce_wp_checkbox( 
array( 
'id'            => '_checkbox', 
'wrapper_class' => 'show_if_simple', 
'label'         => __('HOT Product', 'woocommerce' ), 
'description'   => __( 'Check for Hot Product', 'woocommerce' )
)
);

echo '</div>';

}

function woo_add_custom_general_fields_save( $post_id ){

  $woocommerce_checkbox = isset( $_POST['_checkbox'] ) ? 'yes' : 'no';
  update_post_meta( $post_id, '_checkbox', $woocommerce_checkbox );
}

Related posts

Leave a Reply

1 comment

  1. Your above is working fine. Now you need to display in the front end.
    Try this code:

    add_action('woocommerce_before_single_product_summary','custom_hot_product');
    function custom_hot_product(){
      global $product;
      $is_hot = get_post_meta( $product->id, '_checkbox', true );
      if ( 'yes' == $is_hot ) {
        echo '<span class="hot-product"></span>';
      }
    }
    

    This adds a span with class hot-product if the checkbox is checked. Now style it accordingly.