Skip to content

Instantly share code, notes, and snippets.

@hedqvist
Last active April 9, 2023 13:15
Show Gist options
  • Select an option

  • Save hedqvist/378a5ff37fc126611f5a5c8acaa1a984 to your computer and use it in GitHub Desktop.

Select an option

Save hedqvist/378a5ff37fc126611f5a5c8acaa1a984 to your computer and use it in GitHub Desktop.
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 ) {
case 'dibs':
case 'dibs_invoice':
case 'dibs_masterpass':
case 'dibs_mobilepay':
$invoice['Invoice']['InvoiceType'] = 'CASHINVOICE' ;
$invoice['Invoice']['TermsOfPayment'] = 'DIBS' ;
$invoice['Invoice']['PaymentWay'] = 'CARD' ;
break;
case 'dibs':
case 'stripe':
$invoice['Invoice']['InvoiceType'] = 'CASHINVOICE' ;
$invoice['Invoice']['TermsOfPayment'] = 'STRIPE' ;
$invoice['Invoice']['PaymentWay'] = 'CARD' ;
break;
case 'redlight_swish':
case 'redlight_swish-ecommerce':
$invoice['Invoice']['InvoiceType'] = 'CASHINVOICE';
$invoice['Invoice']['TermsOfPayment'] = 'SWISH';
$invoice['Invoice']['PaymentWay'] = 'CASH';
break;
default:
$invoice['Invoice']['InvoiceType'] = 'INVOICE' ;
}
return $invoice;
}
add_filter('obj_fortnox_update_invoice_params', 'redlight_fortnox_payment_method_invoicetype', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment