php - Making added custom fields in WooComerce product setting pages accessible for compare function -


i have added code:

    // add custom fields product shipping tab     add_action( 'woocommerce_product_options_shipping', 'add_custom_shipping_option_to_products');     function add_custom_shipping_option_to_products(){         global $product_object;          $product_id = method_exists( $product_object, 'get_id' ) ? $product_object->get_id() : $product_object->id;          echo '</div><div class="options_group">'; // new option group          woocommerce_wp_text_input( array(             'id'          => 'custom_text_field1',             'label'       => __( 'weight without foam', 'woocommerce' ),             'placeholder' => 'something',             'desc_tip'    => 'true',             'description' => __( 'weight in decimal form.', 'woocommerce' ),             'value'       => get_post_meta($product_id, '_custom_meta_field1', true),         ) );          woocommerce_wp_text_input( array(             'id'          => 'custom_text_field2',             'label'       => __( 'volume', 'woocommerce' ),             'placeholder' => 'something',             'desc_tip'    => 'true',             'description' => __( 'volume in decimal form.', 'woocommerce' ),             'value'       => get_post_meta($product_id, '_custom_meta_field2', true),         ) );          woocommerce_wp_text_input( array(             'id'          => 'custom_text_field3',             'label'       => __( 'buoyancy', 'woocommerce' ),             'placeholder' => 'something',             'desc_tip'    => 'true',             'description' => __( 'buoyancy in decimal form.', 'woocommerce' ),             'value'       => get_post_meta($product_id, '_custom_meta_field3', true),         ) );      }      // save custom fields values meta data     add_action( 'woocommerce_process_product_meta', 'save_custom_shipping_option_to_products' );     function save_custom_shipping_option_to_products( $post_id ){          $custom_text_field1 = $_post['custom_text_field1'];         if( !empty( $custom_text_field1 ) )             update_post_meta( $post_id, '_custom_meta_field1', esc_attr( $custom_text_field1 ) );          $custom_text_field2 = $_post['custom_text_field2'];         if( !empty( $custom_text_field2 ) )             update_post_meta( $post_id, '_custom_meta_field2', esc_attr( $custom_text_field2 ) );          $custom_text_field3 = $_post['custom_text_field3'];         if( !empty( $custom_text_field3 ) )             update_post_meta( $post_id, '_custom_meta_field3', esc_attr( $custom_text_field3 ) );      }  // add variation external "dimentions" fields add_action( 'woocommerce_product_options_shipping','add_variation_options_built_dimensions', 10, 3 ); function add_variation_options_built_dimensions( $loop, $variation_data, $variation ){      $variation_built_lenght = get_post_meta($variation->id,"_built_lenght", true );     if( ! $variation_built_lenght ) $variation_built_lenght = "";      $variation_built_width = get_post_meta($variation->id,"_built_width", true );     if( ! $variation_built_width ) $variation_built_width = "";      $variation_built_height = get_post_meta($variation->id,"_built_height", true );     if( ! $variation_built_height ) $variation_built_height = "";      ?>     <p class="form-field dimensions_field">         <label for="product_built_length"><?php printf( __( 'ext. dimensions (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ); ?></label>           <span class="wrap">             <input id="product_built_length" placeholder="<?php esc_attr_e( 'built length', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="built_lenght_<?php echo $loop; ?>" value="<?php echo esc_attr( $variation_built_lenght ); ?>" />             <input placeholder="<?php esc_attr_e( 'built width', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="built_width_<?php echo $loop; ?>" value="<?php echo esc_attr( $variation_built_width ); ?>" />             <input placeholder="<?php esc_attr_e( 'built height', 'woocommerce' ); ?>" class="input-text wc_input_decimal last" size="6" type="text" name="built_height_<?php echo $loop; ?>" value="<?php echo esc_attr( $variation_built_height ); ?>" />         </span>         <?php echo wc_help_tip( __( 'lxwxh in decimal form.', 'woocommerce' ) ); ?>      </p>     <?php  }      //save variation custom "dimentions" fields add_action( 'woocommerce_save_product_variation','save_variation_options_built_dimensions', 10 ,2 ); function save_variation_options_built_dimensions( $variation_id, $loop ){      $built_lenght = $_post["built_lenght_$loop"];     if(!empty($built_lenght))         update_post_meta( $variation_id, '_built_lenght', sanitize_text_field($built_lenght) );      $built_width = $_post["built_width_$loop"];     if(!empty($built_width))         update_post_meta( $variation_id, '_built_width', sanitize_text_field($built_width) );      $built_height = $_post["built_height_$loop"];     if(!empty($built_height))         update_post_meta( $variation_id, '_built_height', sanitize_text_field($built_height) ); } ` 

to back-end of product page in woocommerce , need new added fields , parameters automatically used compare function. use yith woocommerce compare plugin compare products. can use there dimensions , weight bak-end products shipping tab , attributes, need use there new added fields. , if possible new data should in compare shown default woocommerce dimension parameter, shown in compare table.

the site can seen here.

thanks.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -