Created
March 21, 2023 07:24
-
-
Save bantunesm/bafedb58d85a8524618d64078d4b0486 to your computer and use it in GitHub Desktop.
Utiliser des champs meta dans la box Données produits de Woocommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ajouter le champ de case à cocher à l'interface d'administration WooCommerce | |
add_action( 'woocommerce_product_options_general_product_data', 'custom_product_checkbox' ); | |
function custom_product_checkbox() { | |
woocommerce_wp_checkbox( array( | |
'id' => 'is_rare', | |
'label' => __( 'Is Rare', 'woocommerce' ), | |
'description' => __( 'Check this box if the product is rare', 'woocommerce' ), | |
'desc_tip' => true, | |
) ); | |
} | |
// Sauvegarder la valeur du champ de case à cocher | |
add_action( 'woocommerce_process_product_meta', 'save_custom_product_checkbox' ); | |
function save_custom_product_checkbox( $post_id ) { | |
$is_rare = isset( $_POST['is_rare'] ) ? 'yes' : 'no'; | |
update_post_meta( $post_id, 'is_rare', $is_rare ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment