WooCommerce: Updating custom Product Variation meta data on Product Page
On the products I have 2 extra meta fields where I can write additional info on the admin.
Actually I added 2 fields “Store 1” and “Store 2” and I can add stock quantities available for each store.
So on the Product Page I’d like to display something like:
Store 1: 20
Store 2: 5
It works perfectly with single product.
But when it comes to variable product I have to display the stock quantites for each variation.
My question is how can I update these fields when the user selects a variation?
(It sould be similar to the SKU, as the user selects a variation the SKU changes.)
I created a custom shortcode which works but doesn’t update when I select a variation on the Product Page:
function store_stock_function() {
global $product;
$id = $product->get_id();
$store1 = get_post_meta( $id, 'store1', true );
$store2 = get_post_meta( $id, 'store2', true );
return 'Store 1: ' . $store1 . '<br/>' . 'Store 2: ' . $store2;
}
add_shortcode('store_stock', 'all_stock_function');
Leave an answer