Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Custom Meta to products on WooCommerce
<?php // Code should be on functions.php
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields() {
global $woocommerce, $post; ?>
<div class="options_group">
<?php
woocommerce_wp_text_input(
array(
'id' => '_email_contacto',
'label' => __( 'Email de Contacto', 'woocommerce' ),
'placeholder' => 'contacto@email.com',
'desc_tip' => 'true',
'description' => __( 'Email de contacto del dueño de la publicación', 'woocommerce' )
)
);
?>
</div>
<?php
}
function woo_add_custom_general_fields_save( $post_id ){
// Text Field
$woocommerce_text_field = $_POST['_email_contacto'];
if( empty( $woocommerce_text_field ) || (is_email($_POST['_email_contacto'])) )
update_post_meta( $post_id, '_email_contacto', esc_attr( $woocommerce_text_field ) );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment