This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function xa_filter_woocommerce_states( $states ) { | |
unset( $states['AF'] ); | |
var_dump( $states ) ; | |
return $states; | |
}; | |
add_filter( 'woocommerce_states', 'xa_filter_woocommerce_states', 10, 1 ); | |
function xa_filter_woocommerce_get_country_locale( $locale ) { | |
$locale['AF']['state']['required'] = true; | |
return $locale; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_cart_calculate_fees','xa_custom_surcharge' ); | |
function xa_custom_surcharge() { | |
global $woocommerce; | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
$state = array('MH'); | |
$surcharge = 10; | |
if ( in_array( WC()->customer->shipping_state, $state ) ) { | |
$woocommerce->cart->add_fee( 'Additional Charge', $surcharge, true, '' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_package_rates' , 'xa_sort_shipping_services_by_cost', 10, 2 ); | |
function xa_sort_shipping_services_by_cost( $rates, $package ) { | |
if ( ! $rates ) return; | |
$rate_cost = array(); | |
foreach( $rates as $rate ) { | |
$rate_cost[] = $rate->cost; | |
} | |
// using rate_cost, sort rates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To test this code, open a private/incognito window, add an item to the cart and then go to cart page. | |
// Once an option is choosen, it will be the default option from that moment onwards. | |
// Code to clear default shipping option. | |
add_filter( 'woocommerce_shipping_chosen_method', '__return_false', 99); | |
// Code to clear default payment option. | |
add_filter( 'pre_option_woocommerce_default_gateway' . '__return_false', 99 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woocommerce_package_rates', 'xa_hide_shipping_rates_when_free_is_available', 10, 2); | |
function xa_hide_shipping_rates_when_free_is_available($rates, $package) | |
{ | |
global $woocommerce; | |
$version = "2.6"; | |
if (version_compare($woocommerce->version, $version, ">=")) { | |
$new_rates = array(); | |
foreach($rates as $key => $rate) { | |
if ('free_shipping' === $rate->method_id || 'local_pickup' === $rate->method_id) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Snippet to hide WooCommerce shipping methods if items of a specific shipping class is not present in the cart | |
add_filter('woocommerce_package_rates', 'xa_hide_shipping_method_when_shipping_class_product_is_in_cart', 10, 2); | |
function xa_hide_shipping_method_when_shipping_class_product_is_in_cart($available_shipping_methods, $package){ | |
// Shipping class IDs that need the method removed | |
$shipping_classes = array( | |
'free-shipping', | |
); | |
$shipping_services_to_hide = array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_checkout_fields' , 'xa_checkout_change_required_fields_to_optional' ); | |
function xa_checkout_change_required_fields_to_optional( $fields ) { | |
$fields['billing']['billing_address_1']['required'] = false; | |
$fields['billing']['billing_address_2']['required'] = false; | |
$fields['billing']['billing_postcode']['required'] = false; | |
$fields['billing']['billing_city']['required'] = false; | |
$fields['billing']['billing_phone']['required'] = false; | |
return $fields; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_package_rates', 'xa_show_shipping_method_based_on_state', 10, 2 ); | |
function xa_show_shipping_method_based_on_state( $available_shipping_methods, $package ) { | |
$states_list = array( 'AK', 'HI', 'PR', 'GU', 'AS', 'VI', 'UM' ); | |
$eligible_services_for_states_list = array( | |
'wf_shipping_usps:flat_rate_box_priority', | |
'wf_shipping_usps:flat_rate_box_express', | |
'wf_shipping_usps:D_FIRST_CLASS', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( ‘hf_csv_order_post_additional_columns’, ‘woocommerce_csv_order_post_add_additional_columns’ , 10 , 1 ); | |
function woocommerce_csv_order_post_add_additional_columns($additional_meta) { | |
$additional_meta = array(‘pdf_invoice_num’ => ‘_invoice_number_display’); // for invoice number | |
$additional_meta[‘wf_order_person’] = ‘wf_order_person’; // for field wf_order_person | |
$additional_meta[‘Body Type’] = ‘Body Type’; // for field Body Type | |
return $additional_meta; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change the default country and state on checkout page. | |
// This works for a new session. | |
add_filter( 'default_checkout_country', 'xa_set_default_checkout_country' ); | |
add_filter( 'default_checkout_state', 'xa_set_default_checkout_state' ); | |
function xa_set_default_checkout_country() { | |
// Returns empty country by default. | |
// return null; | |
// Returns US as default country. | |
return 'US'; | |
} |
OlderNewer