Skip to content

Instantly share code, notes, and snippets.

Avatar

WooForce WooForce

View GitHub Profile
@WooForce
WooForce / functions.php
Created Dec 1, 2016
UPS - Print order note with label
View functions.php
add_filter('wf_ups_shipment_confirm_request_data', 'alter_shipment_request1', 10, 3);
function alter_shipment_request1($data, $order){
if(!empty($order->customer_message)){
$data['Shipment']['Description'] = $order->customer_message;
}
return $data;
}
@WooForce
WooForce / functions.php
Created Oct 22, 2016
Hide shipping method while shipping class available in the package (cart)
View functions.php
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 Slugs that need the method removed
$shipping_classes = array(
'perishable',
);
@WooForce
WooForce / functions.php
Created Oct 14, 2016
DHL Paket - alter createshipment data
View functions.php
add_filter('wf_dhl_paket_create_shipment_request', 'wf_dhl_paket_modify_shipment_request', 10, 2);
function wf_dhl_paket_modify_shipment_request($request, $order){
$street_parts = explode(" ",$order->shipping_address_1);
$request['ShipmentOrder']['Shipment']['Receiver']['Address']['streetName'] = current($street_parts);
$request['ShipmentOrder']['Shipment']['Receiver']['Address']['streetNumber']= end($street_parts);
$request['ShipmentOrder']['Shipment']['Receiver']['Address']['addressAddition']= $order->shipping_address_2;
return $request;
}
@WooForce
WooForce / functions.php
Created Sep 27, 2016
Group shipping rates
View functions.php
add_filter('woocommerce_package_rates', 'wf_group_rates', 10, 2);
function wf_group_rates($rates, $package){
$groups = array(
array(
'group_name'=> 'Mail Express',
'ids' => array('wf_shipping_usps:D_EXPRESS_MAIL','wf_shipping_usps:flat_rate_box_express'),
'operator' => 'min',
),
array(
@WooForce
WooForce / function.php
Last active Sep 16, 2016
Add Purchase Order ( PO ), Invoice, Customer Reference, and Department numbers
View function.php
add_filter('wf_fedex_request','wf_fedex_label_request_reff_callback', 10, 2 );
function wf_fedex_label_request_reff_callback($request,$order){
$po_number = 'x'; //give Purchase Order here
$inv_number = 'x'; // Give Invoice number here
$customs_duties_payer = 'SENDER'; // Give $customs duties payer here
$reff = array();
if( !empty($po_number) && $po_number!='x' )
$reff['CustomerReferences'][] = array( 'CustomerReferenceType' => 'P_O_NUMBER', 'Value' => $po_number );
@WooForce
WooForce / functions.php
Created Sep 14, 2016
FedEx - Show only flat rate for specified class ids except specified states
View functions.php
add_filter('woocommerce_package_rates', 'show_flat_rate_for_specified_class_id', 10, 2);
function show_flat_rate_for_specified_class_id($available_shipping_methods, $package)
{
$exceptional_states = array(
'CA',
'AZ',
'NV',
'NM'
);
@WooForce
WooForce / functions.php
Last active Apr 30, 2021
Split cart into multiple packages based on shipping classes
View functions.php
add_filter( 'woocommerce_cart_shipping_packages', 'wf_split_cart_by_shipping_class_group' );
function wf_split_cart_by_shipping_class_group($packages){
//Reset packages
$packages = array();
//Init splitted package
$splitted_packages = array();
// Group of shipping class ids
$class_groups = array(
@WooForce
WooForce / functions.php
Created Aug 26, 2016
FedEx - Change the customs value and commodity description
View functions.php
add_filter('wf_fedex_request','wf_fedex_label_request_callback', 10, 2 );
function wf_fedex_label_request_callback($request,$order){
$custom_products = array(
'Product-1' => array( //Replace Product-1 with your product name
'Description' => 'sample descrition for product-1', //Enter prodct description here or keep it blank
'Amount' => 150.5 //Enter new amount of produt here or keep it blank
),
'product2' => array(
'Description' => 'sample descrition for product-2',
@WooForce
WooForce / functions.php
Created Aug 26, 2016
FedEx - Tin Number
View functions.php
add_filter('wf_fedex_request','wf_fedex_tin_number', 10, 2 );
function wf_fedex_tin_number($request,$order){
$tintype = "BUSINESS_STATE";
$tin_number ="123456"; //replace tin number here
if(!empty($tin_number)){
$request['RequestedShipment']['Shipper']['Tins'] = array(
'TinType' => $tintype,
'Number' => $tin_number
);
@WooForce
WooForce / functions.php
Created Aug 25, 2016
FedEx-Shipping phone number in the lable
View functions.php
add_filter('wf_fedex_request','my_call_back', 10, 2 );
function my_call_back($request,$order){
$phone = !empty($order->shipping_phone) ? $order->shipping_phone : $order->billing_phone;
$request['RequestedShipment']['Recipient']['Contact']['PhoneNumber'] = $phone;
return $request;
}