Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Filter the available states only for shipping.
- *
- * @author Aelia <support@aelia.co>
- */
- global $filter_shipping_states;
- $filter_shipping_states = false;
- /**
- * Filter the available states. The filter is only applied
- * if the global "filter_shipping_states" is active.
- *
- * @param array states An array of countries and states.
- * @return array An array of countries and states, with the
- * values eventually filtered.
- * @see WC_Countries::get_states()
- * @author Aelia <support@aelia.co>
- */
- add_filter('woocommerce_states', function($states) {
- global $filter_shipping_states;
- if($filter_shipping_states === true) {
- $states['US'] = array(
- 'PA' => 'Pennsylvania',
- );
- }
- return $states;
- });
- /**
- * Enables the filering of states for the shipping calculator
- * on the cart page.
- *
- * @author Aelia <support@aelia.co>
- */
- add_action('woocommerce_before_shipping_calculator', function() {
- global $filter_shipping_states;
- $filter_shipping_states = true;
- });
- /**
- * Enables the filtering of states after the shipping calculator
- * has been rendered,on the cart page.
- *
- * @author Aelia <support@aelia.co>
- */
- add_action('woocommerce_after_shipping_calculator', function() {
- global $filter_shipping_states;
- $filter_shipping_states = false;
- });
- /**
- * Enables the filering of states for the shipping field on the
- * checkout page.
- *
- * @author Aelia <support@aelia.co>
- */
- add_action('woocommerce_form_field_args', function($args, $key, $value) {
- global $filter_shipping_states;
- $filter_shipping_states = ($args['type'] === 'state') && ($key === 'shipping_state');
- return $args;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement