Skip to content

Instantly share code, notes, and snippets.

View shadimanna's full-sized avatar

Shadi Manna shadimanna

View GitHub Profile
@shadimanna
shadimanna / gist:a7bc62eb3dc50145fcd331023c022cf5
Created July 2, 2018 09:12
Do not pass email to DHL API
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;
}
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;
}
}
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;
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;
add_filter('pr_shipping_dhl_base_country', 'my_custom_base_country');
function my_custom_base_country( $base_country ) {
return 'DE';
}
@shadimanna
shadimanna / gist:669913cad84edaea25bfaf415f44a956
Created July 17, 2018 15:06
Modify WooCommerce "shipping_address_2" to be custom address number field
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;
}
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;
}
<?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' ) ) {