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
Created May 2, 2023 10:50
nShift - DoorCode
<?php
/**
* @snippet WooCommerce - Sets customer note as deliveryInstruction in Unifaun
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 7.5.0
*/
function redlight_unifaun_customer_portkod( $shipment, $order ) {
// How to add Custom DoorCode
if(!empty( $order->get_meta('portkod') ) ){
$shipment['receiver']['doorCode'] = $order->get_meta('portkod');
@hedqvist
hedqvist / functions.php
Last active April 18, 2023 09:15
Gordon - Blacklist Saturday, Sunday & Mondays
<?php
/**
* @snippet WooCommerce - Blacklist dates for Gordon Delivery
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 4.9.0
*/
function redlight_gordon_blacklist_certain_days( $date_array ) {
//På söndagar efter 23, hantera det som midnatt
@hedqvist
hedqvist / functions.php
Last active June 30, 2023 12:10
Fortnox - Custom price and discount
<?php
/**
* @snippet WooCommerce - Custom Price functions
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 6.0.0
*/
function redlight_fortnox_order_item_special_price( $orderItem, $item, $product_id, $order ) {
$product = wc_get_product($product_id);
$full_price_products = array('MIL-SATT-40KM','BOM-KOR'); // Out products that should be full price
if( !in_array( $product->get_sku(), $full_price_products ) ){
@hedqvist
hedqvist / functions.php
Last active January 9, 2023 12:34
WordPress - Applications Passwords
<?php
/**
* @snippet WooCommerce - Dont use Application Passwords EVER
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 7.2.0
*/
add_filter('wp_is_application_passwords_available', '__return_false', 10);
@hedqvist
hedqvist / functions.php
Last active January 30, 2025 09:53
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';
@hedqvist
hedqvist / functions.php
Created August 25, 2022 12:43
Fortnox - Stock Amount from QuantityInStock instead of DisposableQuantity
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Hämta lagersaldo från en 'i lager' istället för Disponibelt antal
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 6.8.0
*/
function redlight_fortnox_stock_quantity_in_stock ( $DisposableQuantity, $WC_Product, $fortnox_article ) {
return $fortnox_article->Article->QuantityInStock;
}
add_filter('obj_fortnox_product_stock_amount', 'redlight_fortnox_stock_quantity_in_stock', 10,3 );
@hedqvist
hedqvist / functions.php
Created June 30, 2022 11:52
Fortnox - Dont send over Remarks (Customer note)
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Dont send remarks to fortnox
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 6.0.0
*/
function redlight_fortnox_dont_send_remarks( $orderData, $order_id) {
$orderData['Order']['CopyRemarks'] = false;
$orderData['Order']['Remarks'] = "";
return $orderData;
@hedqvist
hedqvist / functions.php
Created June 30, 2022 09:52
PostNord - Change default Weight
<?php
/**
* @snippet WooCommerce - Set Default Weight per article to 250g (weight is returned in kilograms)
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 6.0.0
*/
function redlight_postnord_default_weight( $default_weight ) {
$default_weight = 0.250;
return $default_weight;
}
<?php
/**
* @snippet WooCommerce - Adds ADDON to Shipment
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 6.0.0
*/
function redlight_unifaun_dhl_addon_spbag( $shipment, $order ) {
// Only ASPO - DHL Service Point
if( 'ASPO' === $shipment['service']['id'] ){
$shipment['service']['addons'][] = array(
@hedqvist
hedqvist / functions.php
Created June 23, 2022 09:28
Fortnox - Itemname Override
<?php
/**
* @snippet WooCommerce - Use item name from WooCommerce
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 6.0.0
*/
function redlight_fortnox_order_item_name( $orderItem, $item, $product_id, $order ) {
$orderItem['Description'] = $item->get_name();
return $orderItem;
}