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 October 5, 2023 07:56
Fortnox - Set custom ordernumber, add this to "YourOrderNumber" in Fortnox
<?php
/**
* @snippet WooCommerce -Fortnox - Set # infront of ordernumber, add this to "YourOrderNumber" in Fortnox
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 8.0.2
*/
function redlight_fortnox_order_ordernumber_prefix( $orderData, $order_id) {
$order = wc_get_order($order_id);
$orderData['Order']['YourOrderNumber'] = $order->get_meta('_custom_order_number', true);
@hedqvist
hedqvist / functions.php
Created November 25, 2019 14:50
Fortnox - Set PhoneNumber to both Phone1 and Phone2 fields in Fortnox
<?php
/**
* @snippet WooCommerce -Fortnox - Set PhoneNumber to Phone2 field in Fortnox
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.8.0
*/
function redlight_fortnox_order_both_phone_fields( $orderData, $order_id) {
$order = new WC_Order($order_id);
$orderData['Order']['Phone2'] = $order->get_billing_phone();
@hedqvist
hedqvist / functions.php
Created November 21, 2019 15:17
Change Return Label date diff for Unifaun
<?php
/**
* @snippet WooCommerce - Sets date difference from Orderdate to display return label button
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.8.0
*/
function redlight_unifaun_return_label_date_diff( $diff ) {
return 60;
}
@hedqvist
hedqvist / functions.php
Created October 31, 2019 10:28
Sets customer note as reference in Unifaun
<?php
/**
* @snippet WooCommerce - Sets customer note as reference in Unifaun
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.7.0
*/
function redlight_unifaun_customer_note_as_reference( $shipment, $order ) {
if(!empty( $order->get_customer_note() ) ){
$shipment['senderReference'] = $order->get_customer_note();
}
@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
@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
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
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 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
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;