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
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 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
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
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
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();
@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
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
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 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 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' );