mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
20 lines
688 B
Text
20 lines
688 B
Text
add_action( 'woocommerce_product_options_general_product_data', 'wc_add_badge_checkbox_to_products' );
|
|
|
|
function wc_add_badge_checkbox_to_products() {
|
|
woocommerce_wp_checkbox( array(
|
|
'id' => 'custom_badge',
|
|
'class' => '',
|
|
'label' => 'Show Custom Badge'
|
|
)
|
|
);
|
|
}
|
|
|
|
add_action( 'save_post', 'wc_save_badge_checkbox_to_post_meta' );
|
|
|
|
function wc_save_badge_checkbox_to_post_meta( $product_id ) {
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
|
return;
|
|
if ( isset( $_POST['custom_badge'] ) ) {
|
|
update_post_meta( $product_id, 'custom_badge', $_POST['custom_badge'] );
|
|
} else delete_post_meta( $product_id, 'custom_badge' );
|
|
}
|