Created
March 1, 2015 19:33
-
-
Save full-stack-king/8f990e787fd83413c67a to your computer and use it in GitHub Desktop.
WC Custom product meta
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 | |
// 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; | |
echo '<div class="options_group">'; | |
// Custom fields will be created here... | |
// Text Field | |
woocommerce_wp_text_input( | |
array( | |
'id' => 'vi_produt_count', | |
'label' => __( 'Product count', 'woocommerce' ), | |
'placeholder' => 'Enter split count', | |
'desc_tip' => 'true', | |
'description' => __( 'Enter the custom product count here.', 'woocommerce' ) | |
) | |
); | |
echo '</div>'; | |
} | |
function woo_add_custom_general_fields_save( $post_id ){ | |
// Text Field | |
$woocommerce_text_field = $_POST['vi_produt_count']; | |
if( !empty( $woocommerce_text_field ) ) | |
update_post_meta( $post_id, 'vi_produt_count', esc_attr( $woocommerce_text_field ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found in http://www.remicorson.com/mastering-woocommerce-products-custom-fields/