Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. //custom data tab
  2. add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' , 99 , 1 );
  3. add_action( 'woocommerce_product_data_panels', 'add_my_custom_product_data_fields',10,3 );
  4. add_action( 'woocommerce_process_product_meta','woocommerce_process_product_meta_fields_save',10,2 );
  5.  
  6.  
  7. function add_my_custom_product_data_tab( $product_data_tabs ) {
  8. $product_data_tabs['my-custom-tab'] = array(
  9. 'label' => __( 'My Custom Tab', 'my_text_domain' ),
  10. 'target' => 'my_custom_product_data',
  11. );
  12. return $product_data_tabs;
  13. }
  14.  
  15.  
  16. function add_my_custom_product_data_fields() {
  17. global $woocommerce, $post;
  18. echo '<div id="my_custom_product_data" class="panel woocommerce_options_panel">';
  19.  
  20. woocommerce_wp_textarea_input(
  21. array(
  22. 'id' => '_textarea[' . $post->ID . ']',
  23. 'label' => __( 'My Textarea', 'woocommerce' ),
  24. 'placeholder' => '',
  25. 'description' => __( 'Enter the custom value here.', 'woocommerce' ),
  26. 'value' => get_post_meta( $post->ID, '_textarea', true ),
  27. )
  28. );
  29.  
  30. echo '</div>';
  31. }
  32.  
  33.  
  34. function woocommerce_process_product_meta_fields_save( $post_id ){
  35.  
  36. // Textarea
  37. $textarea = $_POST['_textarea'][ $post_id ];
  38. if( ! empty( $textarea ) ) {
  39. update_post_meta( $post_id, '_textarea', esc_attr( $textarea ) );
  40. }
  41.  
  42. }
  43.  
  44. echo get_post_meta( $post->ID, 'my-field-slug', true );
  45. ex. echo get_post_meta( $post->ID, '_textarea', true );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement