Skip to content

Instantly share code, notes, and snippets.

View hedqvist's full-sized avatar

Christopher Hedqvist hedqvist

View GitHub Profile
@hedqvist
hedqvist / functions.php
Last active November 3, 2020 11:51
Swish - Agelimit
<?php
/**
* @snippet WooCommerce - Age-limit set to 18
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.6.0
*/
function redlight_swish_age_limit( $data, $order ) {
$data['ageLimit'] = 18;
return $data;
}
@hedqvist
hedqvist / functions.php
Created September 15, 2020 06:43
Unifaun - Force Weight
<?php
/**
* @snippet WooCommerce - Adds Default weight to parcel
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.5.1
*/
function redlight_unifaun_force_minimum_weight( $shipment, $order) {
foreach( $shipment['parcels'] as $i => $parcel ) {
$shipment['parcels'][$i]['weight'] = 0;
}
@hedqvist
hedqvist / functions.php
Created September 9, 2020 10:33
Fortnox - External Invoice Reference
<?php
/**
* @snippet WooCommerce - Adds ordernumber to Fortnox ExternalInvoiceReference2 field
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.5.0
*/
function redlight_fortnox_invoice_order_reference( $orderData, $order_id) {
$order = wc_get_order($order_id);
$orderData['Order']['ExternalInvoiceReference2'] = $order->get_order_number();
@hedqvist
hedqvist / functions.php
Created September 8, 2020 11:56
Unifaun - PreNOT
<?php
/**
* @snippet WooCommerce - Adds ADDON to Shipment
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.2.0
*/
function redlight_unifaun_prenot( $shipment, $order ) {
// Only PUA and 'Varubrev - Lämnas vid dörr'
if( 'P19' === $shipment['service']['id'] ){
$shipment['service']['addons'][] = array(
@hedqvist
hedqvist / functions.php
Created August 24, 2020 08:41
Unifaun - SecurityDeclaration
<?php
/**
* @snippet WooCommerce -Unifaun - Set Customs Security printset
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.0
*/
function redlight_unifaun_customs_security( $customsDeclaration, $shipment, $order_id) {
//$order = new WC_Order($order_id);
if( 'BREKI' === $shipment['service']['id'] ){
$customsDeclaration['printSet'] = ['SECURITY'];
@hedqvist
hedqvist / functions.php
Last active August 24, 2020 08:19
Automatic Printing - Different printer for packingslip
<?php
/**
* @snippet WooCommerce - Print to different printerID if we are printing a packingslip
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.4.0
*/
function redlight_print_packingslip_to_custom_printer($printjob, $order) {
if( strpos($printjob['title'], 'Packingslip') !== false) {
$printjob['printerId'] = 123456;
}
@hedqvist
hedqvist / functions.php
Last active August 27, 2020 08:10
Automatic Printing - Custom Printer ID
<?php
/**
* @snippet WooCommerce - Print to different printerID depending on shipment method
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.4.0
*/
function redlight_print_labels_to_customer_printer($printjob, $order) {
if( strpos($printjob['title'], 'Packingslip') !== false) {
return $printjob;
}
@hedqvist
hedqvist / functions.php
Last active August 27, 2020 08:09
Unifaun - Small Labels for PUE
<?php
/**
* @snippet WooCommerce - Sets size of shippinglabel to 107x72 (thermo-brev3)
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.4.0
*/
function redlight_unifaun_pacsoft_pdf_label( $pdf_config, $order ) {
if( 'Brev i posten' === $order->get_shipping_method() || 'Fri frakt' === $order->get_shipping_method() || 'Free delivery' === $order->get_shipping_method() || 'Postage' === $order->get_shipping_method() ){
$pdf_config['target1Media'] = 'thermo-brev3';
}
@hedqvist
hedqvist / functions.php
Created August 13, 2020 10:00
DB Schenker - Ombud Retur
<?
/**
* @snippet WooCommerce - Adds ADDON to Shipment
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.9.0
*/
function redlight_unifaun_bhp_return( $shipment, $order ) {
// Only Schenker Ombud
if( 'BHP' === $shipment['service']['id'] ){
$shipment['service']['addons'][] = array(
@hedqvist
hedqvist / gist:8ade7e4e81dee657439b770979cb4950
Created August 12, 2020 13:14
Fortnox - Klarna Reference
<?php
/**
* @snippet WooCommerce - Adds Klarna Invoice and ordernumber to Fortnox ExternalInvoiceReference1 & ExternalInvoiceReference2 fields
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.0.5
*/
function redlight_fortnox_klarna_invoice_order_reference( $orderData, $order_id) {
$order = new WC_Order($order_id);
$klarna_invoice_number = get_post_meta( $order->id, '_klarna_invoice_number', true );
$klarna_order_reservation = get_post_meta( $order->id, '_klarna_order_reservation', true );