Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // Create Woocommerce Custom Field (here called Base Name)
  2. add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
  3. function woo_add_custom_general_fields() {
  4.  
  5. global $woocommerce, $post;
  6. echo '<div class="options_group">';
  7.  
  8. // Make our text field with the following
  9. woocommerce_wp_text_input(
  10. array(
  11. 'id' => 'base_name',
  12. 'label' => __( 'Base Name Field', 'woocommerce' ),
  13. 'placeholder' => 'base name text here',
  14. 'desc_tip' => 'true',
  15. 'description' => __( 'Enter the custom value here.', 'woocommerce' )
  16. )
  17. );
  18.  
  19. echo '</div>';
  20.  
  21. }
  22. // Save to the wpbd when we update the product pages (post)
  23. add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
  24. function woo_add_custom_general_fields_save( $post_id ){
  25.  
  26. $woocommerce_text_field = $_POST['base_name']; // Text Field
  27. if( !empty( $woocommerce_text_field ) ) update_post_meta( $post_id, 'base_name', esc_attr( $woocommerce_text_field ) );
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement