Skip to content

Instantly share code, notes, and snippets.

@hedqvist
Last active January 30, 2025 09:53
Show Gist options
  • Save hedqvist/ef4c7a8c556d424e8cc6764c47e5325a to your computer and use it in GitHub Desktop.
Save hedqvist/ef4c7a8c556d424e8cc6764c47e5325a to your computer and use it in GitHub Desktop.
PostNord - Papersize depending on Shipping method
<?php
/**
* @snippet WooCommerce - Sets size of shippinglabel to LETTER for certain orders and LABEL for certain
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 7.2.0
*/
function redlight_postnord_papersize( $papersize, $order ) {
$shipping_method = $order->get_shipping_method();
if( in_array( $shipping_method, array( 'Ombud', 'Hemleverans' ) ) ){
$papersize = 'LABEL';
}
if( in_array( $shipping_method, array( 'Varubrev' ) ) ){
$papersize = 'LETTER';
}
return $papersize;
}
add_filter('redlight_wcpns_get_label_papersize', 'redlight_postnord_papersize', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment