Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Created October 27, 2022 10:18
Show Gist options
  • Save Asikur22/9d893bd8b96718fdd4e9a394b665f028 to your computer and use it in GitHub Desktop.
Save Asikur22/9d893bd8b96718fdd4e9a394b665f028 to your computer and use it in GitHub Desktop.
Add Meta Box to Woocommerce Product #WooMeta
/*
* Product Meta Fields
*/
add_action( 'woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields' );
function woocommerce_product_custom_fields() {
global $product_object;
echo '<div class="product_custom_field">';
// Custom Product Text Field
woocommerce_wp_text_input( array(
'id' => 'tipologiaAppunto',
'label' => __( 'Tipologia appunto:', 'woocommerce' ),
'placeholder' => '',
'desc_tip' => 'true' // <== Not needed as you don't use a description
) );
echo '</div>';
}
/*
* Save admin product custom setting field(s) values
*/
add_action( 'woocommerce_admin_process_product_object', 'woocommerce_product_custom_fields_save' );
function woocommerce_product_custom_fields_save( $product ) {
if ( isset( $_POST['tipologiaAppunto'] ) ) {
$product->update_meta_data( 'tipologiaAppunto', sanitize_text_field( $_POST['tipologiaAppunto'] ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment