I'm trying to write a specific function that allow to change automatically the product shipping class when a WooCommerce custom field is set with a specific value.
Please find below the screenshot about the custom fields
This is the code I had thought of but obviously it doesn't work.
function woo_on_product_save( $post_id ) {
$title = $product->get_meta( 'meta_easyfatt_libero_1' );
if ( $title = 'Trenta' ) {
$shipping_class_id = 1182;
}
$product = wc_get_product( $post_id );
$product->set_shipping_class_id( $shipping_class_id );
$product->save();
}
add_action( 'woocommerce_process_product_meta', 'woo_on_product_save', 100 );
Any suggestions would be greatly appreciated!
