title: Replace variation price range with custom field in Woocommerce
body: <p>I am adding and saving a custom field to my variable products using the following functions:</p>
  
  <pre><code>add_action( 'woocommerce_product_options_inventory_product_data', 'wc_add_custom_fields' );
  
  function wc_add_custom_fields() {
  
      woocommerce_wp_text_input(
           array(
               'id'                =&gt; '_custom_product_pricekg_field',
               'label'             =&gt; __( 'Price per kg', 'woocommerce' ),
               'placeholder'       =&gt; '',
              'desc_tip'            =&gt; false,
               'description'       =&gt; __( "Here's some really helpful text that appears next to the field.", 'woocommerce' ),
               'type'              =&gt; 'number',
               'custom_attributes' =&gt; array(
                       'step'     =&gt; 'any',
                       'min'    =&gt; '0'
                   )
           )
       );    
  
  }
  
  add_action( 'woocommerce_process_product_meta', 'wc_custom_fields_save' );
  
  function wc_custom_fields_save($post_id)
  {
  
      $woocommerce_custom_product_pricekg_field = $_POST['_custom_product_pricekg_field'];
      if (!empty($woocommerce_custom_product_pricekg_field))
          update_post_meta($post_id, '_custom_product_pricekg_field', esc_attr( $_POST['_custom_product_pricekg_field'] ) );
  }
  </code></pre>
  
  <p>I would like to replace the variable price range ($XX-XX) on all archive and product pages with this custom field. I don't know how to do this. The below snippet replaces the variable price range with the default variable, perhaps this could be modified to show my custom field value?</p>
  
  <pre><code>add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
  
  function custom_variation_price( $price, $product ) {
  
      foreach($product-&gt;get_available_variations() as $pav){
          $def=true;
          foreach($product-&gt;get_variation_default_attributes() as $defkey=&gt;$defval){
              if($pav['attributes']['attribute_'.$defkey]!=$defval){
                  $def=false;             
              }   
          }
          if($def){
              $price = $pav['display_price'];         
          }
      }   
      return woocommerce_price($price);
  }
  </code></pre>