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 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 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 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
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 November 21, 2018 11:10
Remove Postmeta from order row in Fortnox
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Remove and Post_meta rows in Fortnox via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_remove_postmeta($orderData) {
foreach($orderData['Order']['OrderRows'] as $i => $item) {
if(isset($item['AccountNumber']) && $item['AccountNumber'] == 'API_BLANK')
unset($orderData['Order']['OrderRows'][$i]);
@hedqvist
hedqvist / functions.php
Last active April 9, 2023 13:14
Company name as Name and customer name as YourReference
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Company Name to Fortnox order Name
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.3.5
*/
function redlight_fortnox_order_companyname( $orderData, $order_id) {
$order = new WC_Order($order_id);
if(!empty($order->get_billing_company())){
$orderData['Order']['CustomerName'] = $order->get_billing_company();
@hedqvist
hedqvist / functions.php
Last active June 1, 2023 07:53
Add custom field to customer GUEST USERS
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - (GUEST USERS) Set $our_custom_field as Comments on Customer
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.4.2
*/
function redlight_fortnox_guest_customer_data( $customer, $order_id ) {
$order = wc_get_order( $order_id );
$our_custom_field = $order->get_meta('our_custom_field');
@hedqvist
hedqvist / functions.php
Created July 5, 2018 06:46
Custom field to REGISTRED USERS in Fortnox
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - (REGISTRED USERS) Set $our_custom_field as Comment field to Fortnox via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.0.6
*/
function redlight_custom_customerdata( $customer) {
$our_custom_field = (!empty($_POST['our_custom_field'])) ? $_POST['our_custom_field'] : "";
@hedqvist
hedqvist / functions.php
Created June 12, 2018 13:01
Dont copy remarks to invoice
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Dont copy remarks
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_dont_copy_remarks( $orderData, $order_id) {
$orderData['Order']['CopyRemarks'] = false;
return $orderData;
}
@hedqvist
hedqvist / functions.php
Created June 11, 2018 09:40
Add order currency to Fortnox order-data
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add order currency to Fortnox
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.3.5
*/
function redlight_fortnox_order_currency( $orderData, $order_id) {
$order = new WC_Order($order_id);
$orderData['Order']['Currency'] = $order->get_currency();
return $orderData;