Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //custom data tab
- add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' , 99 , 1 );
- add_action( 'woocommerce_product_data_panels', 'add_my_custom_product_data_fields',10,3 );
- add_action( 'woocommerce_process_product_meta','woocommerce_process_product_meta_fields_save',10,2 );
- function add_my_custom_product_data_tab( $product_data_tabs ) {
- $product_data_tabs['my-custom-tab'] = array(
- 'label' => __( 'My Custom Tab', 'my_text_domain' ),
- 'target' => 'my_custom_product_data',
- );
- return $product_data_tabs;
- }
- function add_my_custom_product_data_fields() {
- global $woocommerce, $post;
- echo '<div id="my_custom_product_data" class="panel woocommerce_options_panel">';
- woocommerce_wp_textarea_input(
- array(
- 'id' => '_textarea[' . $post->ID . ']',
- 'label' => __( 'My Textarea', 'woocommerce' ),
- 'placeholder' => '',
- 'description' => __( 'Enter the custom value here.', 'woocommerce' ),
- 'value' => get_post_meta( $post->ID, '_textarea', true ),
- )
- );
- echo '</div>';
- }
- function woocommerce_process_product_meta_fields_save( $post_id ){
- // Textarea
- $textarea = $_POST['_textarea'][ $post_id ];
- if( ! empty( $textarea ) ) {
- update_post_meta( $post_id, '_textarea', esc_attr( $textarea ) );
- }
- }
- echo get_post_meta( $post->ID, 'my-field-slug', true );
- ex. echo get_post_meta( $post->ID, '_textarea', true );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement