Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create Woocommerce Custom Field (here called Base Name)
- add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
- function woo_add_custom_general_fields() {
- global $woocommerce, $post;
- echo '<div class="options_group">';
- // Make our text field with the following
- woocommerce_wp_text_input(
- array(
- 'id' => 'base_name',
- 'label' => __( 'Base Name Field', 'woocommerce' ),
- 'placeholder' => 'base name text here',
- 'desc_tip' => 'true',
- 'description' => __( 'Enter the custom value here.', 'woocommerce' )
- )
- );
- echo '</div>';
- }
- // Save to the wpbd when we update the product pages (post)
- add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
- function woo_add_custom_general_fields_save( $post_id ){
- $woocommerce_text_field = $_POST['base_name']; // Text Field
- if( !empty( $woocommerce_text_field ) ) update_post_meta( $post_id, 'base_name', esc_attr( $woocommerce_text_field ) );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement