Skip to content

Instantly share code, notes, and snippets.

View WooForce's full-sized avatar

WooForce WooForce

View GitHub Profile
@WooForce
WooForce / functions.php
Last active March 31, 2016 11:59
Hide shipping rates based on the quantities of items
add_filter( 'woocommerce_package_rates', 'wf_adjust_shipping_rate', 10, 2 );
function wf_adjust_shipping_rate( $available_shipping_methods, $packages ){
// Total quantity is total unit
$unit = 0;
$apply_final_filter = TRUE;
foreach ( $packages['contents'] as $item ) {
$unit+=$item['quantity'];
}
// if unit less than 3 , show D_FIRST_CLASS only
@WooForce
WooForce / functions.php
Last active March 31, 2016 11:59
Exclude undesired First Class Mail services on WooForce USPS Plugin
// Exclude the services First-Class Mail Postcards, First-Class Mail Large Envelope and First-Class Mail Stamped Letter
add_filter('usps_disable_first_class_rate_first-class-mail-postcards', 'disable_first_class_rate_for_this_service',10,3);
add_filter('usps_disable_first_class_rate_first-class-mail-large-envelope', 'disable_first_class_rate_for_this_service',10,3);
add_filter('usps_disable_first_class_rate_first-class-mail-stamped-letter', 'disable_first_class_rate_for_this_service',10,3);
function disable_first_class_rate_for_this_service() {
return true;
}
// Include First-Class Mail Parcel ( Default Behaviour)
add_filter('usps_disable_first_class_rate_first-class-mail-parcel', 'disable_first_class_rate_for_parcel_service',10,3);
@WooForce
WooForce / functions.php
Last active March 31, 2016 11:59
WooForce FedEx Plugin - Change recipient's phone number on Label
add_filter('wf_fedex_request','my_call_back', 10, 2 );
function my_call_back($request,$order){
$request['RequestedShipment']['Recipient']['Contact']['PhoneNumber']='123-123-1234';
return $request;
}
@WooForce
WooForce / functions.php
Last active March 31, 2016 12:00
WooCommerce: Hide the undesired method for the particular existing shipping class
add_filter('woocommerce_package_rates', 'hide_auspost_method_when_shipping_class_product_is_in_cart', 10, 2);
function hide_auspost_method_when_shipping_class_product_is_in_cart($available_shipping_methods, $package)
{
$shipping_class_ids = array(
16
);
$shipping_services_to_hide = array(
'wf_australia_post:AUS_PARCEL_REGULAR',
'wf_australia_post:AUS_PARCEL_EXPRESS',
@WooForce
WooForce / functions.php
Last active March 31, 2016 12:00
WooCommerce: Hide a shipping method for the particular product(s)
add_filter('woocommerce_package_rates', 'hide_shipping_method_if_particular_product_available_in_cart', 10, 2);
function hide_shipping_method_if_particular_product_available_in_cart($available_shipping_methods)
{
global $woocommerce;
// products_array should be filled with all the products ids
// for which shipping method (stamps) to be restricted.
$products_array = array(
@WooForce
WooForce / functions.php
Last active March 31, 2016 12:00
WooCommerce: Hide the undesired service for the required Zip Codes
add_filter('woocommerce_package_rates', 'wf_remove_shipping_options_for_particular_zip_codes', 10, 2);
function wf_remove_shipping_options_for_particular_zip_codes($rates, $package)
{
global $woocommerce;
$excluded_zip_array = array(
'93999'
);
if (in_array($woocommerce->customer->get_shipping_postcode() , $excluded_zip_array)) {
unset($rates['wf_fedex_woocommerce_shipping:FEDEX_GROUND']);
@WooForce
WooForce / functions.php
Last active March 31, 2016 12:00
WooCommerce: Hide the undesired service for the required states
add_filter('woocommerce_package_rates', 'wf_hide_undesired_service_for_required_states', 10, 2);
function wf_hide_undesired_service_for_required_states($rates, $package)
{
$exclude = array(
'international_delivery' => array(
'CA'
) ,
'wf_fedex_woocommerce_shipping:FEDEX_GROUND' => array(
'FL'
@WooForce
WooForce / functions.php
Last active March 31, 2016 12:01
WooCommerce: To show Shipping Methods when Shipping Class exist
add_filter( 'woocommerce_package_rates', 'show_shippingpro_method_when_shipping_class_product_is_in_cart', 10, 2 );
function show_shippingpro_method_when_shipping_class_product_is_in_cart( $available_shipping_methods, $package ) {
$shipping_class_ids = array(
16);
$shipping_services_to_show = array(
'wf_woocommerce_shipping_pro:Group1Express',
'wf_woocommerce_shipping_pro:group2Standard',
);
$shipping_services_to_show = array_map('strtolower', $shipping_services_to_show);
$shipping_class_exists = false;
@WooForce
WooForce / functions.php
Last active March 31, 2016 12:01
WooCommerce: If you are using Calculation Mode as Per Item/Per Category/Per Shipping and would like to offer a free shipping based on order value.
add_filter('woocommerce_package_rates', 'wf_remove_shipping_pro_rate_when_free_shipping_is_applicable', 10, 2);
function wf_remove_shipping_pro_rate_when_free_shipping_is_applicable($rates, $package)
{
if (isset($rates['free_shipping'])) {
foreach($rates as $ratekey => $ratevalue) {
if (strpos($ratekey, 'wf_woocommerce_shipping_pro:') !== false) {
unset($rates[$ratekey]);
}
}
@WooForce
WooForce / functions.php
Last active March 31, 2016 12:02
WooCommerce: Hide a shipping method for a particular Shipping Class
add_filter('woocommerce_package_rates', 'hide_shipping_method_when_shipping_class_product_is_in_cart', 10, 2);
function hide_shipping_method_when_shipping_class_product_is_in_cart($available_shipping_methods, $package)
{
// Shipping class IDs that need the method removed
$shipping_class_ids = array(
1111,
2232,