Advanced: Actions and filters

Hem » WooCommerce » WooCommerce Fortnox Integration » Advanced: Actions and filters

Coming soon!

This part is under construction and will be enhanced with explanations for the actions and filters. Meanwhile it is still possible to use this post as some sort of a reference, it might still help you finding the right spot in the code!

Actions

do_action('fortnox_before_order_sync', array( $order ) );
do_action('wf_order_before_create_or_update', array( $order ) );
do_action('fortnox_after_order_sync', array( $order ));
do_action('wf_order_after_create_or_update', $order );
do_action( 'wetail_fortnox_after_product_price_update', $product->get_id(), $sku, $price_list );
do_action('wf_order_after_product_price_update', $product->get_id(), $sku, $price_list );
do_action('wf_order_after_refund', $order, $refunded_order );

Filters

$fortnox_customer = apply_filters('wf_customer_before_post', [
    'Email'                 => $address['email'],
    'EmailInvoice'          => $address['email'],
    'Name'                  => ! empty( $address['company'] ) ? $address['company'] : $address['first_name'] . ' ' . $address['last_name'],
    'Type'                  => ( ! empty( $address['company'] ) ? "COMPANY" : "PRIVATE" ),
    'OrganisationNumber'    => get_post_meta( $order->get_id(), '_billing_company_number', true ),
    'Address1'              => $order->get_billing_address_1() ? $order->get_billing_address_1() : $order->get_shipping_address_1(),
    'Address2'              => $order->get_billing_address_2() ? $order->get_billing_address_2() : $order->get_shipping_address_2(),
    'ZipCode'               => $order->get_billing_postcode() ? $order->get_billing_postcode() : $order->get_shipping_postcode(),
    'City'                  => $order->get_billing_city() ? $order->get_billing_city() : $order->get_shipping_city(),
    'CountryCode'           => $order->get_billing_country() ? $order->get_billing_country() : $order->get_shipping_country(),
    'DeliveryAddress1'      => $order->get_shipping_address_1(),
    'DeliveryAddress2'      => $shipping_address2,
    'DeliveryCity'          => $order->get_shipping_city(),
    'Currency'              => $order->get_currency(),
    'DeliveryCountryCode'   => $order->get_shipping_country() ? $order->get_shipping_country() : $order->get_billing_country() ,
    'DeliveryName'          => $order->get_shipping_first_name()." ".$order->get_shipping_last_name(),
    'DeliveryZipCode'       => $order->get_shipping_postcode(),
    'Phone1'                => $address['phone'],
    'ShowPriceVATIncluded'  => false,
    'Active'                => true,
], $order->get_user());
apply_filters('wetail_fortnox_sync_modify_customer', [
    'Email'                 => $address['email'],
    'EmailInvoice'          => $address['email'],
    'Name'                  => ! empty( $address['company'] ) ? $address['company'] : $address['first_name'] . ' ' . $address['last_name'],
    'Type'                  => ( ! empty( $address['company'] ) ? "COMPANY" : "PRIVATE" ),
    'OrganisationNumber'    => get_post_meta( $order->get_id(), '_billing_company_number', true ),
    'Address1'              => $order->get_billing_address_1() ? $order->get_billing_address_1() : $order->get_shipping_address_1(),
    'Address2'              => $order->get_billing_address_2() ? $order->get_billing_address_2() : $order->get_shipping_address_2(),
    'ZipCode'               => $order->get_billing_postcode() ? $order->get_billing_postcode() : $order->get_shipping_postcode(),
    'City'                  => $order->get_billing_city() ? $order->get_billing_city() : $order->get_shipping_city(),
    'CountryCode'           => $order->get_billing_country() ? $order->get_billing_country() : $order->get_shipping_country(),
    'DeliveryAddress1'      => $order->get_shipping_address_1(),
    'DeliveryAddress2'      => $shipping_address2,
    'DeliveryCity'          => $order->get_shipping_city(),
    'Currency'              => $order->get_currency(),
    'DeliveryCountryCode'   => $order->get_shipping_country() ? $order->get_shipping_country() : $order->get_billing_country() ,
    'DeliveryName'          => $order->get_shipping_first_name()." ".$order->get_shipping_last_name(),
    'DeliveryZipCode'       => $order->get_shipping_postcode(),
    'Phone1'                => $address['phone'],
    'ShowPriceVATIncluded'  => false,
], $order->get_user());
apply_filters( 'woocommerce_order_number', $order_id, $order )
apply_filters( 'wf_invoice_before_create_or_update', $invoice, $order );
apply_filters( 'wetail_fortnox_invoice_before_fortnox_submit', $invoice, $order );
apply_filters( 'woocommerce_order_number', $refunded_order->get_id(), $refunded_order )
apply_filters( 'woocommerce_order_number', $order->get_id(), $order );
apply_filters( 'wf_invoice_payment_before_create_or_update', [
    "AmountCurrency"            => $order->get_total(),
    "InvoiceNumber"             => $response->Order->InvoiceReference,
    "PaymentDate"               => substr( $order->get_date_created(), 0, 10 ),
    "ModeOfPaymentAccount"      => self::get_payment_account( $order->get_payment_method() )
], $order )
apply_filters( 'wetail_fortnox_invoice_payment', [
    "AmountCurrency"            => $order->get_total(),
    "InvoiceNumber"             => $response->Order->InvoiceReference,
    "PaymentDate"               => substr( $order->get_date_created(), 0, 10 ),
    "ModeOfPaymentAccount"      => self::get_payment_account( $order->get_payment_method() )
], $order )
apply_filters( 'woocommerce_order_number', $order_id, $order )
apply_filters( 'wf_order_payload_before_create_or_update', [
    'CustomerNumber'            => $customer_number,
    'DocumentNumber'            => $order_number,
    'YourOrderNumber'           => apply_filters( 'woocommerce_order_number', $order_id, $order ),
    'ExternalInvoiceReference1' => apply_filters( 'woocommerce_order_number', $order_id, $order ),
    'OrderDate'                 => substr( $order->get_date_created(), 0, 10 ), # To cut off order time
    'VATIncluded'               => apply_filters( 'wf_order_vat_included', false ),
    'Currency'                  => $order->get_currency(),
], $order )
apply_filters( 'woocommerce_order_number', $order_id, $order )
apply_filters( 'wf_order_vat_included', false )
apply_filters( 'wetail_fortnox_order', [
    'CustomerNumber'            => $customer_number,
    'DocumentNumber'            => $order_number,
    'YourOrderNumber'           => apply_filters( 'woocommerce_order_number', $order_id, $order ),
    'ExternalInvoiceReference1' => apply_filters( 'woocommerce_order_number', $order_id, $order ),
    'OrderDate'                 => substr( $order->get_date_created(), 0, 10 ), # To cut off order time
    'VATIncluded'               => apply_filters( 'wetail_fortnox_sync_order_vat_included', false ),
    'Currency'                  => $order->get_currency(),
], $order )
apply_filters( 'wetail_fortnox_sync_order_vat_included', false )
apply_filters( 'wf_order_row_payload_before_create_or_update', [
    'ArticleNumber'     => WF_Products::sanitized_sku( $product->get_sku() ),
    'Description'       => WF_Products::sanitize_description( $product_name ),
    'DeliveredQuantity' => $item->get_quantity(),
    'OrderedQuantity'   => $item->get_quantity(),
    'Unit'              => "st",
    'Price'             => $subtotal,
    'Discount'          => self::calculate_item_discount( $subtotal, $total, $item->get_quantity() ),
    'DiscountType'      => "AMOUNT",
    'VAT'               => self::get_tax( $order, $product, $customer ),
], $product, $item )
apply_filters( 'wetail_fortnox_sync_modify_order_row', [
    'ArticleNumber'     => WF_Products::sanitized_sku( $product->get_sku() ),
    'Description'       => WF_Products::sanitize_description( $product_name ),
    'DeliveredQuantity' => $item->get_quantity(),
    'OrderedQuantity'   => $item->get_quantity(),
    'Unit'              => "st",
    'Price'             => $subtotal,
    'Discount'          => self::calculate_item_discount( $subtotal, $total, $item->get_quantity() ),
    'DiscountType'      => "AMOUNT",
    'VAT'               => self::get_tax( $order, $product, $customer ),
], $product, $item )
apply_filters( 'wf_order_row_sales_account', false, $order, $item )
apply_filters( 'wetail_fortnox_modify_order_row_sales_account', false, $order, $item )
apply_filters( 'wf_order_shipping_account', $shipping_account, $order )
apply_filters( 'wetail_fortnox_shipping_account', $shipping_account, $order )
apply_filters( 'wf_custom_shipping',[
    'AccountNumber'     => $shipping_account,
    'Description'       => $shipping_product->get_title(),
    'DeliveredQuantity' => 1,
    'OrderedQuantity'   => 1,
    'Unit'              => "st",
    'Price'             => $order->get_total_shipping(),//TODO
    'Discount'          => 0,
    'DiscountType'      => "AMOUNT",
    'VAT'               => $tax_rate
], $order )
apply_filters( 'wf_order_way_of_delivery', array_key_exists('WayOfDelivery', $fortnox_order ) ? $fortnox_order['WayOfDelivery'] : '', $shipping )
apply_filters( 'wetail_fortnox_way_of_delivery', array_key_exists('WayOfDelivery', $fortnox_order ) ? $fortnox_order['WayOfDelivery'] : '', $shipping )
apply_filters( 'wf_order_terms_of_delivery', array_key_exists('TermsOfDelivery', $fortnox_order ) ? $fortnox_order['TermsOfDelivery'] : '' , $shipping )
apply_filters( 'wetail_fortnox_terms_of_delivery', array_key_exists('TermsOfDelivery', $fortnox_order ) ? $fortnox_order['TermsOfDelivery'] : '' , $shipping )
apply_filters( 'wf_product_payload_before_create_or_update', [
   'ArticleNumber' => $sku,
   'Description'   => self::get_formatted_title( $product ),
   'Type'          => $product->is_virtual() ? 'SERVICE' : 'STOCK',
])
apply_filters( 'wetail_fortnox_sync_product_article', [
    'ArticleNumber' => $sku,
    'Description'   => self::get_formatted_title( $product ),
    'Type'          => $product->is_virtual() ? 'SERVICE' : 'STOCK',
])
apply_filters( 'wf_order_payload_before_create_or_update', [
    'CustomerNumber'            => $customer_number,
    'DocumentNumber'            => $order_number,
    'YourOrderNumber'           => $order_number,
    'ExternalInvoiceReference1' => $order_number,
    'OrderDate'                 => substr( $refunded_order->get_date_created(), 0, 10 ), # To cut off order time
    'VATIncluded'               => apply_filters( 'wf_order_vat_included', false ),
    'Currency'                  => $refunded_order->get_currency(),
], $refunded_order )
apply_filters( 'wf_order_vat_included', false )
apply_filters( 'woocommerce_order_number', $refunded_order_id, $refunded_order )
apply_filters( 'wf_order_row_payload_before_create_or_update', [
    'ArticleNumber'     => WF_Products::sanitized_sku( $product->get_sku() ),
    'Description'       => WF_Products::sanitize_description( $product_name ),
    'DeliveredQuantity' => $item->get_quantity(),
    'OrderedQuantity'   => $item->get_quantity(),
    'Unit'              => "st",
    'Price'             => $subtotal,
    'Discount'          => WF_Orders::calculate_item_discount( $subtotal, $total, $item->get_quantity() ),
    'DiscountType'      => "AMOUNT",
    'VAT'               => WF_Orders::get_tax( $order, $product, $customer ),
], $product, $item )
apply_filters( 'wf_order_row_sales_account', false, $order, $item )
apply_filters( 'wf_order_shipping_account', $shipping_account, $order )