Skip to content

Instantly share code, notes, and snippets.

Avatar

Shadi Manna shadimanna

View GitHub Profile
View Faire - Zero ordered item price
add_filter('faire_add_to_order_product', 'faire_product_price_zero');
function faire_product_price_zero( $product ) {
$product['item']->price_cents = 0;
return $product;
}
View Sale of goods for customs
// Override DHL Label Export Type, and return "Sale of goods"
add_filter( 'pr_shipping_dhl_paket_label_shipment_export_type' , 'custom_dhl_export_type', 10, 1 );
function custom_dhl_export_type($type) {
return 'COMMERCIAL_GOODS';
}
View Remove state if does not have at least 2 chars
add_filter('pr_shipping_dhl_label_args', 'maybe_remove_state', 10, 2);
function maybe_remove_state($args, $order_id) {
if( isset( $args['shipping_address']['state'] ) && ( strlen( $args['shipping_address']['state'] ) < 2 || strlen( $args['shipping_address']['state'] ) > 20 ) ) {
unset($args['shipping_address']['state']);
}
return $args;
}
View Change customs item description
add_filter('pr_shipping_dhl_label_args', 'modify_item_sku', 10, 2);
function modify_item_sku($args, $order_id) {
if( isset( $args['items'] ) ) {
foreach ($args['items'] as $item_key => $item_value) {
$item_value['item_description'] = "ENTER THE DESCRIPTION YOU WANT";
}
}
return $args;
}
View Modify order id to order number
add_filter('pr_shipping_dhl_label_args', 'modify_order_id_to_number', 10, 2);
function modify_order_id_to_number($args, $order_id) {
$order = wc_get_order( $order_id );
$args['dhl_settings']['dhl_label_ref'] = $order->get_order_number();
return $args;
}
View Add Company Name to DPI API Call
add_filter('pr_shipping_dhl_label_args', 'maybe_add_company', 10, 2);
function maybe_add_company($args, $order_id) {
if( ! empty( $args['shipping_address']['company'] ) ) {
if( ! empty( $args['shipping_address']['address_2'] ) ) {
$args['shipping_address']['address_2'] = $args['shipping_address']['address_1'] . ', ' . $args['shipping_address']['address_2'];
} else {
$args['shipping_address']['address_2'] = $args['shipping_address']['address_1'];
}
$args['shipping_address']['address_1'] = $args['shipping_address']['company'];
}
View Add or Update Post Number
add_filter('pr_shipping_dhl_label_args', 'modify_post_number', 10, 2);
function modify_post_number($args, $order_id) {
if( $order_id == 12345 ){
$args['shipping_address']['dhl_postnum'] = 54321;
}
return $args;
}
@shadimanna
shadimanna / Weight in DE
Created Jan 20, 2021
Return flat weight value if Germany shipping destination
View Weight in DE
add_filter('pr_shipping_dhl_order_weight', 'custom_add_weight', 10, 2);
function custom_add_weight($total_weight, $order_id) {
$order = wc_get_order( $order_id );
if ($order) {
$shipping_address = $order->get_address( 'shipping' );
if( $shipping_address['country'] == 'DE' ) {
return 30;
}
}
@shadimanna
shadimanna / gist:d1c32e93dad8008dddd9151b69e0994c
Last active Aug 19, 2020
Do not pass phone number to DHL API
View gist:d1c32e93dad8008dddd9151b69e0994c
add_filter('pr_shipping_dhl_label_args', 'remove_phone_number', 10, 2);
function remove_phone_number($args, $order_id) {
if(isset($args['shipping_address']['phone'])){
unset($args['shipping_address']['phone']);
}
return $args;
}
View gist:a7bc62eb3dc50145fcd331023c022cf5
add_filter('pr_shipping_dhl_label_args', 'remove_email_number', 10, 2);
function remove_email_number($args, $order_id) {
if(isset($args['shipping_address']['email'])){
unset($args['shipping_address']['email']);
}
return $args;
}