Skip to content

Instantly share code, notes, and snippets.

View WooForce's full-sized avatar

WooForce WooForce

View GitHub Profile
@WooForce
WooForce / functions.php
Created April 6, 2016 09:51
Change the default "no available shipping methods" message on cart/checkout page
add_filter( 'woocommerce_cart_no_shipping_available_html', 'change_msg_no_available_shipping_methods', 10, 1 );
add_filter( 'woocommerce_no_shipping_available_html', 'change_msg_no_available_shipping_methods', 10, 1 );
function change_msg_no_available_shipping_methods( $default_msg ) {
$custom_msg = "Call us for quotation - 1-800-XXX-XXXX";
if( empty( $custom_msg ) ) {
return $default_msg;
}
return $custom_msg;
}
@WooForce
WooForce / functions.php
Last active April 22, 2016 07:45
Canada Post - Add a custom description while printing label.
add_filter('wf_canadapost_request','wf_canadapost_label_request_callback', 10, 2 );
function wf_canadapost_label_request_callback($request,$order){
$custom_product_description = 'My product description'; // This text might not exceed 35 characters
$xml = new SimpleXMLElement($request);
if($xml->{'delivery-spec'}->{'destination'}->{'address-details'}->{'country-code'} != 'CA'){ //if international
$ref_no = $xml->{'delivery-spec'}->{'references'}->{'customer-ref-1'};
$custom_text = $ref_no.", ".$custom_product_description;
$xml->{'delivery-spec'}->{'references'}->{'customer-ref-1'} = substr($custom_text,0,35);
@WooForce
WooForce / functions.php
Last active April 8, 2016 00:24
FedEx - Change Commodities details description.
add_filter('wf_fedex_request','wf_fedex_label_request_callback', 10, 2 );
function wf_fedex_label_request_callback($request,$order){
$custom_product_description = 'My Product Description';
$commodities = !empty( $request['RequestedShipment']['CustomsClearanceDetail']['Commodities'] ) ? $request['RequestedShipment']['CustomsClearanceDetail']['Commodities']: array() ;
foreach ($commodities as $product_id => $value) {
$request['RequestedShipment']['CustomsClearanceDetail']['Commodities'][$product_id]['Description'] = $custom_product_description;
}
return $request;
}
@WooForce
WooForce / functions.php
Created April 4, 2016 09:47
FedEx - Add custom customs description / customer reference
add_filter('wf_fedex_request','wf_fedex_label_request_callback', 10, 2 );
function wf_fedex_label_request_callback($request,$order){
$custom_product_description = 'My Product Description';
$request['CustomerReferences'][] = array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => $custom_product_description );
$RequestedPackageLineItems = !empty( $request['RequestedShipment']['RequestedPackageLineItems'] ) ? $request['RequestedShipment']['RequestedPackageLineItems'] : array() ;
$flag = 0;
@WooForce
WooForce / functions.php
Last active September 24, 2020 21:46
Introduce vendor names along with standard labels across shipping packages
define("PV_ATTRIBUTE", "vendor");
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Check if WooCommerce is active
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
if ( ! class_exists( 'TH_Shipping_Options' ) ) {
class TH_Shipping_Options {
/**
@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(