Good Day, I have been trying to figure out how to select shipping class programmatically using php. I'm creating a woocommerce product from frontend using a form and on form submission the product is created but i can get to make any of the shipping class to be selected. below is the screenshot showing the shipping class setup on the product created from frontend with the inspect element tab showing the ids (as value) of the shipping classes
i'm using the below code to select the phone Shipping Fee Class
$pShipping_Class = 25; //Where 25 is the id/value for Phone Shipping Fee Class
update_post_meta( $product_id, 'product_shipping_class', $pShipping_Class );
The update_post_meta works for every other field even the custom dropdown field i created i was able to use update_post_meta( $product_id, '_list_of_stores', 'custom-order' ); to select the value custom-order from the custom dropdown field i created but when i tried same thing for the shipping class, it doesn't work. Not sure what i'm doing wrong.
Please point me in the right direction. how can i update the shipping class using php. i already have the IDs and slug.
Thanks
UPDATE: I realized that when i manually select the Phone Shipping Fee and hit the Update product button. it added selected property (i.e selected="selected" ), see screenshot below;
Please how to i make this update/select any of the shipping class (either by IDs or slug), as the shipping class need to be updated on the fly to give users the shipping rate of the product they created and added to cart.

