Skip to content

Instantly share code, notes, and snippets.

@full-stack-king
Created March 1, 2015 19:33
Show Gist options
  • Save full-stack-king/8f990e787fd83413c67a to your computer and use it in GitHub Desktop.
Save full-stack-king/8f990e787fd83413c67a to your computer and use it in GitHub Desktop.
WC Custom product meta
<?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 ) );
}
@full-stack-king
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment