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:15
Sätter Fakturatyp och Betalsätt baserat på betalsätt i WooCommerce :)
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Set InvoiceType depending on payment method via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_payment_method_invoicetype($invoice, $order_id) {
$order = wc_get_order($order_id);
$order_payment_method = $order->get_payment_method();
switch( $order_payment_method ) {
@hedqvist
hedqvist / functions.php
Created February 27, 2018 18:50
Set InvoiceDate based on OrderDate via functions.php
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Set InvoiceDate based on OrderDate via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_payment_method_invoicedate($invoice, $order_id) {
$order = new WC_Order($order_id);
$invoice['Invoice']['InvoiceDate'] = $order->get_date_created()->format("Y-m-d");
@hedqvist
hedqvist / functions.php
Created May 7, 2018 08:19
Klarna External references Fortnox
<?php
/**
* @snippet WooCommerce - Adds Klarna Invoice and ordernumber to Fortnox ExternalInvoiceReference1 & ExternalInvoiceReference2 fields
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.3.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 );
@hedqvist
hedqvist / functions.php
Last active April 9, 2023 13:14
Add Company name to Fortnox Order/Customer
<?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
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;
@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 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
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
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
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]);