WooCommerce shipping method filter based on shipping-class and ship to state.
<?php
<?php
add_filter( 'woocommerce_available_shipping_methods', 'custom_shipping_methods' );function custom_shipping_methods( $available_methods ) {$carrier = 'ups';foreach ( WC()->cart->cart_contents AS $item ) {if ( has_term( 'large-item', 'product_shipping_class', $item['product_id'] ) ) {$carrier = 'usps';continue;
}}$states = array( 'AK', 'HI' );if ( ! in_array( WC()->customer->get_state(), $states ) ) {$available_methods = wp_filter_object_list( $available_methods, array( 'method_id' => $carrier ), 'NOT' );}return $available_methods;}Add this code in your theme function.php file.
No comments:
Post a Comment