Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Adds "Product CPE Hours" field to WooCommerce Products
- */
- // Display Fields
- add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
- // Save Fields
- add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
- function woocommerce_product_custom_fields()
- {
- global $woocommerce, $post;
- echo '<div class="product_custom_field">';
- //Custom Product CPE Hours Field
- woocommerce_wp_text_input(
- array(
- 'id' => '_product_cpe_hours',
- 'placeholder' => 'Course CPE Hours',
- 'label' => __('Course CPE Hours', 'woocommerce'),
- 'type' => 'number',
- 'custom_attributes' => array(
- 'step' => 'any',
- 'min' => '0'
- )
- )
- );
- echo '</div>';
- }
- function woocommerce_product_custom_fields_save($post_id)
- {
- // Custom Product CPE Hours Field
- $woocommerce_product_cpe_hours = $_POST['_product_cpe_hours'];
- if (!empty($woocommerce_product_cpe_hours))
- update_post_meta($post_id, '_product_cpe_hours', esc_attr($woocommerce_product_cpe_hours));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement