Это мой код до сих пор. < /p>
Код: Выделить всё
add_action( 'woocommerce_process_product_meta', 'update_stock_from_custom_field', 10, 1 );
function update_stock_from_custom_field( $post_id ) {
$additional_stock = get_post_meta( $post_id, 'stock_loja1', true );
if ( $additional_stock != 0 ) {
$product = wc_get_product( $post_id );
if ( $product ) {
$current_stock = $product->get_stock_quantity( 'edit' );
$new_stock = $current_stock + $additional_stock;
update_post_meta( $post_id, '_stock', $new_stock );
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... tom-fields