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 );
}
Your above is working fine. Now you need to display in the front end.
Try this code:
This adds a
span
with classhot-product
if the checkbox is checked. Now style it accordingly.