Code that I am using giving errorI have added this code still getting error in checkout page and can’t move to paypal. How to remove it.
add_filter( ‘woocommerce_checkout_fields’, ‘remove_shipping_validation_for_variable_products’ );
function remove_shipping_validation_for_variable_products( $fields ) {
// Enter the product IDs of the variable products for which you want to remove shipping validation
$product_ids = array( 1932, 1923, 1913 );
if ( ! empty( WC()->cart ) ) {
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product_id = $cart_item['product_id'];
if ( in_array( $product_id, $product_ids ) ) {
unset( $fields['shipping']['shipping_country']['validate'] );
unset( $fields['shipping']['shipping_state']['validate'] );
unset( $fields['shipping']['shipping_city']['validate'] );
unset( $fields['shipping']['shipping_address_1']['validate'] );
unset( $fields['shipping']['shipping_postcode']['validate'] );
break; // Stop the loop after finding the first matching product
}
}
}
return $fields;
}
Still getting error message There are no shipping options available. Please ensure that your address has been entered correctly, or contact us if you need any help.
How to remove it for set of products id.