You may use this code to reproduce custom field into variable product. Then go to the xml feed and try to get the value from variation_meta_price_kc
or variation_meta_price_kc_sale
. It will not be listed there. Could we use some snippet to get it there? Did not find any documentation with snippets for the plugin. Thank you!
By the way: This input may be also for some label only, does not have to be for price so if you have some variable you could use variable meta for any purpose, but into the feed you can not get it. I think this is the same problem as @silvo37 has and the reason why he statred this topic here.
add_action( 'woocommerce_variation_options_pricing', 'bbloomer_add_custom_field_to_variations', 10, 3 );
function bbloomer_add_custom_field_to_variations( $loop, $variation_data, $variation ) {
woocommerce_wp_text_input( array(
'id' => 'variation_meta_price_kc[' . $loop . ']',
'class' => 'short wc_input_price',
'label' => __( 'Regular price (K?)', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, 'variation_meta_price_kc', true )
) );
woocommerce_wp_text_input( array(
'id' => 'variation_meta_price_kc_sale[' . $loop . ']',
'class' => 'short wc_input_price',
'label' => __( 'Sale price (K?)', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, 'variation_meta_price_kc_sale', true )
) );
}
add_action( 'woocommerce_save_product_variation', 'bbloomer_save_custom_field_variations', 10, 2 );
function bbloomer_save_custom_field_variations( $variation_id, $i ) {
$custom_fieldkc = $_POST['variation_meta_price_kc'][$i];
$custom_fieldkcs = $_POST['variation_meta_price_kc_sale'][$i];
if ( isset( $custom_fieldkc ) ) update_post_meta( $variation_id, 'variation_meta_price_kc', esc_attr( $custom_fieldkc ) );
if ( isset( $custom_fieldkcs ) ) update_post_meta( $variation_id, 'variation_meta_price_kc_sale', esc_attr( $custom_fieldkcs ) );
}
-
This reply was modified 2 years, 3 months ago by mikel555.