Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // 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 Checkbox Field
- woocommerce_wp_checkbox(
- array(
- 'id' => '_custom_product_checkbox_field',
- 'placeholder' => 'Custom Product Checkbox Field',
- 'label' => __('Custom Product Checkbox Field', 'woocommerce'),
- 'desc_tip' => 'true'
- )
- );
- echo '</div>';
- }
- // Saving Values
- function woocommerce_product_custom_fields_save($post_id){
- // Custom Product Text Field
- $woocommerce_custom_product_checkbox_field = $_POST['_custom_product_checkbox_field'];
- if (!empty($woocommerce_custom_product_checkbox_field ))
- update_post_meta($post_id, '_custom_product_checkbox_field', esc_attr($woocommerce_custom_product_checkbox_field ));
- }
- ?>
- function add_engrave_text_field() {
- if (is_single('product-url-a')) {
- echo 'Enter your chosen letters: <span id="character_count"></span>
- <div><table class="variations" cellspacing="0">
- <tbody>
- <tr>
- <td class="value"><label class="product-custom-text-label" for="custom_text">Custom Text</label></td>
- <td class="value">
- <label><input type="text" class="product-counter" name="engrave_text" placeholder="Enter Your Custom Letters ..." maxlength="3" /></label>
- </td>
- </tr>
- </tbody>
- </table></div>';
- }
- }
- add_action( 'woocommerce_before_add_to_cart_button', 'add_engrave_text_field', 0 );
- // Display Fields
- add_action('woocommerce_product_options_general_product_data', 'product_custom_fields_add');
- function product_custom_fields_add(){
- echo '<div class="product_custom_field">';
- // Custom Product Checkbox Field
- woocommerce_wp_checkbox(
- array(
- 'id' => '_engrave_text_option',
- 'desc' => __('set custom Engrave text field', 'woocommerce'),
- 'label' => __('Display custom Engrave text field', 'woocommerce'),
- 'desc_tip' => 'true'
- )
- );
- echo '</div>';
- }
- // Save Fields
- add_action('woocommerce_process_product_meta', 'product_custom_fields_save');
- function product_custom_fields_save($post_id){
- // Custom Product Text Field
- if ( ! empty( $_POST['_engrave_text_option'] ) )
- update_post_meta($post_id, '_engrave_text_option', esc_attr( $_POST['_engrave_text_option'] ));
- }
- add_action( 'woocommerce_before_add_to_cart_button', 'add_engrave_text_field', 0 );
- function add_engrave_text_field() {
- global $post;
- // Get the checkbox value
- $engrave_option = get_post_meta( $post->ID, '_engrave_text_option', true );
- // If is single product page and have the "engrave text option" enabled we display the field
- if ( is_product() && ! empty($engrave_option) ) {
- ?>
- <div>
- <label class="product-custom-text-label" for="engrave_text"><?php _e( 'Engraving option:', 'woocommerce'); ?><br>
- <input style="min-width:220px" type="text" class="product-counter" name="engrave_text" placeholder="<?php _e( 'Enter Your Custom Letters ...', 'woocommerce'); ?>" maxlength="3" />
- </label>
- </div><br>
- <?php
- }
- }
- add_action( 'woocommerce_before_add_to_cart_button', 'add_engrave_text_field', 0 );
- function add_engrave_text_field() {
- global $post;
- // Get the checkbox value
- $engrave_option = get_post_meta( $post->ID, '_engrave_text_option', true );
- // If is single product page and have the "engrave text option" enabled we display the field
- if ( is_product() && ! empty($engrave_option) ) {
- ?>
- <div>
- <label class="product-custom-text-label" for="engrave_text"><?php _e( 'Engraving option:', 'woocommerce'); ?><br>
- <input style="min-width:220px" type="text" class="product-counter" name="engrave_text" placeholder="<?php _e( 'Enter Your Custom Letters ...', 'woocommerce'); ?>" maxlength="3" />
- </label>
- </div><br>
- <?php
- }
- }
Add Comment
Please, Sign In to add comment