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 December 13, 2017 22:24
Klarna reference to Fortnox ExternalInvoiceReference1 & ExternalInvoiceReference2
<?
/**
* @snippet WooCommerce - Adds Klarna Invoice and ordernumber to Fortnox ExternalInvoiceReference1 & ExternalInvoiceReference2 fields
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_klarna_invoice_order_reference( $orderData, $order_id) {
$order = new WC_Order($order_id);
if($order->get_payment_method() == 'klarna_checkout'){
@hedqvist
hedqvist / functions.php
Last active July 12, 2018 14:44
Shipping Fee to OrderRow in Fortnox
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add Shipping charges as OrderItem instead of Shipping fee in Fortnox via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_shipping_as_orderLine($orderData, $order_id) {
$order = new WC_Order($order_id);
// Remove fee from orderData
@hedqvist
hedqvist / functions.php
Created January 5, 2018 20:05
Remove Postmeta from OrderItem
<?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')
@hedqvist
hedqvist / functions.php
Last active November 26, 2020 11:16
Set TermsOfPayment depending on payment method
<?
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Set TermsOfPayment depending on payment method via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_payment_method_TermsOfPayment($orderData, $order_id) {
$order = wc_get_order($order_id);
$order_payment_method = $order->get_payment_method();
switch( $order_payment_method ) {
@hedqvist
hedqvist / functions.php
Created January 17, 2018 10:17
Change 'Return to shop' from cart
<?
/**
* @snippet WooCommerce - Changes return to shop redirect that usually appears on cart-page via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_wc_cart_to_shop_redirect_url() {
return 'https://example.com/your-page/';
}
add_filter( 'woocommerce_return_to_shop_redirect', 'redlight_wc_cart_to_shop_redirect_url' );
@hedqvist
hedqvist / functions.php
Created January 17, 2018 10:24
Add content after "Proceed to checkout"
<?php
/**
* @snippet WooCommerce - Add content after "Proceed to checkout" button via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
redlight_wc_cart_after_procced_to_checkout(){
$checkout_url = 'https://example.com/your-page/';
?>
<a href="<?php echo $checkout_url; ?>" class="checkout-button button alt wc-forward"><?php _e( 'Continue shopping', 'woocommerce' ); ?></a>
@hedqvist
hedqvist / functions.php
Created January 18, 2018 17:03
Do not sync retailer product (where SKU ends in _1)
<?
function check_sync_woocommerce_product($check, $product_id){
$wc_product = wc_get_product($product_id);
$sku = $wc_product->get_sku();
$sku_chnk = explode('_', $sku);
$to_sync = (int) end($sku_chnk) == 1 ? false : true;
if($to_sync){
return $check;
@hedqvist
hedqvist / functions.php
Created January 18, 2018 17:36
Add WooCommerce currency
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add WooCommerce currency via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.5
*/
function redlight_fortnox_currency($orderData, $order_id) {
$orderData['Order']['Currency'] = get_woocommerce_currency();
return $orderData;
}
@hedqvist
hedqvist / functions.php
Last active November 9, 2022 13:05
Add EAN code to article in Fortnox
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add EAN code to article in Fortnox via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.6
*/
function redlight_fortnox_ean( $article, $product_id) {
$ean_string = get_post_meta( $product_id, 'EAN', true );
$article['Article']['EAN'] = $ean_string;
@hedqvist
hedqvist / functions.php
Last active January 23, 2023 12:56
Add payment method title to Fortnox order-comments
<?php
/**
* @snippet WooCommerce - Fortnox plugin by Redlight Media - Add payment method title to Fortnox order-comments via functions.php
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.2.6
*/
function redlight_fortnox_payment_method_title( $orderData, $order_id) {
$order = wc_get_order($order_id);
$orderData['Order']['Remarks'] .= "\r\n"."Betalsätt: ".$order->get_payment_method_title();