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 April 9, 2023 13:14
Fortnox AdministrativeFee
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add fee to AdministrativeFee via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_administrative_fee( $orderData, $order_id ) {
// Get the total fees of this order
$order = wc_get_order($order_id);
$fees = $order->get_fees();
@hedqvist
hedqvist / functions.php
Created January 18, 2019 18:06
Update article name when updating products in Fortnox
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Update Article name to article in Fortnox via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.5.3
*/
function redlight_update_article( $article, $product_id) {
$WC_Product = wc_get_product($product_id);
$article->Article['Description'] = $WC_Product->get_name();
@hedqvist
hedqvist / functions.php
Created February 8, 2019 13:27
Ordernumber in ExternalReference 1
<?php
/**
* @snippet WooCommerce - Adds ordernumber to Fortnox ExternalInvoiceReference1 field
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.5.3
*/
function redlight_fortnox_order_external_reference( $orderData, $order_id) {
$order = new WC_Order($order_id);
$orderData['Order']['ExternalInvoiceReference1'] = $order->get_order_number();
@hedqvist
hedqvist / functions.php
Created March 8, 2019 08:29
Angry Creative Unifaun - Schenker Dimensions on Parcel
<?php
/**
* @snippet WooCommerce - Adds Dimensions to Schenker Parcel
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.5.3
*/
function redlight_unifaun_schenker_dimensions( $shipment, $order) {
if( 'BHP' === $shipment['service']['id'] ){
foreach( $shipment['parcels'] as $i => $parcel ) {
$shipment['parcels'][$i]['length'] = 240;
@hedqvist
hedqvist / functions.php
Created April 1, 2019 16:45
Add default weight to parcels in Unifaun
<?php
/**
* @snippet WooCommerce - Adds Default weight to parcel
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.5.3
*/
function redlight_unifaun_minimum_weight( $shipment, $order) {
foreach( $shipment['parcels'] as $i => $parcel ) {
if( $shipment['parcels'][$i]['weight'] < 0.150 ){
$shipment['parcels'][$i]['weight'] = 0.150;
@hedqvist
hedqvist / functions.php
Created May 7, 2019 18:17
Swish Payment Request Message
<?php
/**
* @snippet WooCommerce - Swish Ecommerce by Redlight Media - Justera meddelande i betalningsförfrågan till att endast innehåll ordernummer
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.6.2
*/
function redlight_swish_ecommerce_paymentrequest_message_ordernumber ( $message, $order ) {
$message = $order->get_order_number();
return $message;
}
@hedqvist
hedqvist / functions.php
Last active November 18, 2021 10:17
Set Unifaun pdf size
<?php
/**
* @snippet WooCommerce - Sets size of shippinglabel to 107x190 (thermo-190)
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.5.3
*/
function redlight_unifaun_pacsoft_pdf_label( $pdf_config, $order ) {
$pdf_config['target1Media'] = 'thermo-190';
@hedqvist
hedqvist / functions.php
Created August 1, 2019 08:36
Custom logic to check for offer - YITH Request a quote
<?php
/**
* @snippet WooCommerce - Custom Logic for YITH Request a Quote
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.6.2
*/
function redlight_fortnox_ywraq( $is_offer, $order_id ) {
$order = new WC_Order($order_id);
if( 'yes' === $order->get_meta('ywraq_raq',true) ){
$is_offer = true;
@hedqvist
hedqvist / functions.php
Created August 13, 2019 07:58
Unifaun - senderReference
<?php
/**
* @snippet WooCommerce - Sets custom reference in Unifaun
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.7.0
*/
function redlight_unifaun_reference( $shipment, $order ) {
$shipment['senderReference'] = 'TOP-' . $order->get_order_number();
@hedqvist
hedqvist / functions.php
Last active October 13, 2019 12:40
Sync order on another status
<?php
add_action('woocommerce_order_status_changed', array($this, 'redlight_custom_update_woocommerce_order_status'), 10, 3);
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Sync order on "on-hold"
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.7.0
*/
public function redlight_custom_update_woocommerce_order_status($order_id, $old_status, $new_status) {
if ('on-hold' == $new_status):
// cCheck if this order should be created as offer