Skip to content

Instantly share code, notes, and snippets.

Avatar

Shadi Manna shadimanna

View GitHub Profile
View Download File
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// $file = sanitize_file_name( $_GET['path'] );
// sanitize path
$file = realpath( $_GET['path'] );
// echo $file;
if ( current_user_can( 'edit_shop_orders' ) && check_admin_referer( 'download-dhl-label' ) ) {
View gist:6751305c06a852b972247af0e595d145
add_filter('pr_shipping_dhl_order_weight', 'custom_add_weight', 10, 2);
function custom_add_weight($total_weight, $order_id) {
$total_weight += 1; // Add any weight needed, units of measure will be whatever is set in WooCommerce
return $total_weight;
}
@shadimanna
shadimanna / gist:669913cad84edaea25bfaf415f44a956
Created Jul 17, 2018
Modify WooCommerce "shipping_address_2" to be custom address number field
View gist:669913cad84edaea25bfaf415f44a956
add_filter('pr_shipping_dhl_label_args', 'custom_shipping_address_no', 10, 2);
function custom_shipping_address_no($args, $order_id) {
$args['shipping_address']['address_2'] = get_post_meta($order_id, 'my_custom_address_no', true); // Set to your custom address number field, most likely a order meta data
return $args;
}
View Modify base country
add_filter('pr_shipping_dhl_base_country', 'my_custom_base_country');
function my_custom_base_country( $base_country ) {
return 'DE';
}
View Modify Free Products
add_filter('pr_shipping_dhl_label_args', 'modify_item_price', 10, 2);
function modify_item_price($args, $order_id) {
if( isset( $args['items'] ) ) {
foreach ($args['items'] as $item_key => $item_value) {
if( $item_value['item_value'] == 0 ) {
$args['items'][ $item_key ]['item_value'] = 0.01;
}
}
}
return $args;
View Ensure Item Price 2 Decimal Float
add_filter('pr_shipping_dhl_label_args', 'modify_item_price', 10, 2);
function modify_item_price($args, $order_id) {
if( isset( $args['items'] ) ) {
foreach ($args['items'] as $item_key => $item_value) {
if( isset( $item_value['item_value'] ) ) {
$args['items'][ $item_key ]['item_value'] = round( floatval( $item_value['item_value'] ), 2);
}
}
}
return $args;
View Change SKU argument to Product ID
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) {
if( isset( $item_value['sku'] ) ) {
$product_id = wc_get_product_id_by_sku( $item_value['sku'] );
if( $product_id ) {
$args['items'][ $item_key ]['sku'] = $product_id;
}
}
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 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;
}
@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;
}