Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /**
  2. * Adds "Product CPE Hours" field to WooCommerce Products
  3. */
  4.  
  5.  
  6. // Display Fields
  7. add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
  8.  
  9. // Save Fields
  10. add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
  11.  
  12.  
  13. function woocommerce_product_custom_fields()
  14. {
  15. global $woocommerce, $post;
  16. echo '<div class="product_custom_field">';
  17.  
  18. //Custom Product CPE Hours Field
  19. woocommerce_wp_text_input(
  20. array(
  21. 'id' => '_product_cpe_hours',
  22. 'placeholder' => 'Course CPE Hours',
  23. 'label' => __('Course CPE Hours', 'woocommerce'),
  24. 'type' => 'number',
  25. 'custom_attributes' => array(
  26. 'step' => 'any',
  27. 'min' => '0'
  28. )
  29. )
  30. );
  31.  
  32. echo '</div>';
  33.  
  34. }
  35.  
  36. function woocommerce_product_custom_fields_save($post_id)
  37. {
  38. // Custom Product CPE Hours Field
  39. $woocommerce_product_cpe_hours = $_POST['_product_cpe_hours'];
  40. if (!empty($woocommerce_product_cpe_hours))
  41. update_post_meta($post_id, '_product_cpe_hours', esc_attr($woocommerce_product_cpe_hours));
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement