Skip to content

Instantly share code, notes, and snippets.

@BKeanu1989
Created September 6, 2019 13:36
Show Gist options
  • Save BKeanu1989/88950572b392878d2c39a87daff6aa80 to your computer and use it in GitHub Desktop.
Save BKeanu1989/88950572b392878d2c39a87daff6aa80 to your computer and use it in GitHub Desktop.
function woo_add_product_gender() {
echo '<div class="options_group">';
woocommerce_wp_select(
array(
'id' => '_product_gender',
'label' => __( 'Gender', 'woocommerce' ),
'options' => array(
'male' => __( 'Male', 'woocommerce' ),
'female' => __( 'Female', 'woocommerce' ),
'unisex' => __( 'Unisex', 'woocommerce' )
)
)
);
echo '</div>';
}
function woo_add_product_gender_save( $post_id ) {
$woocommerce_dropdown_field = $_POST['_product_gender'];
if ( !empty( $woocommerce_dropdown_field )) {
update_post_meta( $post_id , '_product_gender', esc_attr( $woocommerce_dropdown_field ));
}
}
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_product_gender' );
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_product_gender_save' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment