Created
December 28, 2017 12:31
-
-
Save ldgarc/b225b0eb6b72571c95b0174ef6fe4173 to your computer and use it in GitHub Desktop.
Add Custom Meta to products on 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
<?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' => '[email protected]', | |
'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