WooCommerce Fortnox Actions and Filters
wf_eu_vat_meta_key
Description:
This filter allows you to modify the meta key used for storing the EU VAT number in order or customer metadata.
Variables:
$meta_key (string): The default meta key for storing the VAT number. This could be something like _eu_vat_number.
Usage Example:
add_filter('wf_eu_vat_meta_key', function($meta_key) {
return '_custom_vat_number';
});
This would change the meta key to _custom_vat_number.
wf_eu_vat_number
Description:
Filters the EU VAT number before it is used or stored.
Variables:
$vat_number (string): The EU VAT number associated with the order or customer.
Usage Example:
add_filter('wf_eu_vat_number', function($vat_number) {
return strtoupper($vat_number); // Convert VAT number to uppercase.
});
wf_eu_vat_number_is_valid
Description:
Filters the boolean result of a VAT number validation check.
Variables:
$is_valid (bool): The result of the validation, true if valid, false otherwise.
Usage Example:
add_filter('wf_eu_vat_number_is_valid', function($is_valid, $vat_number) {
return custom_vat_validation($vat_number);
}, 10, 2);
wf_customer_url
Description:
Filters the URL endpoint used to communicate with the Fortnox API for customer data.
Variables:
$url (string): The Fortnox API URL for the customer endpoint.
Usage Example:
add_filter('wf_customer_url', function($url) {
return $url . '?additional_param=true';
});
wf_customer_before_post
Description:
Filters the customer data before it is sent to Fortnox.
Variables:
$customer_data (array): An array containing customer details such as name, address, and VAT number.
Usage Example:
add_filter('wf_customer_before_post', function($customer_data) {
$customer_data['name'] = sanitize_text_field($customer_data['name']);
return $customer_data;
});
wf_customer_vat_info
Description:
Filters the VAT information of a customer before it is sent to Fortnox.
Variables:
$vat_info (array): Contains VAT details such as VAT number and VAT status.
Usage Example:
add_filter('wf_customer_vat_info', function($vat_info) {
$vat_info['vat_status'] = 'active';
return $vat_info;
});
wf_refund_invoice_payload_before_create
Description: Filters the payload data for a refund invoice before it is created in Fortnox.
Variables:
$payload (array): Contains the invoice details such as line items, amounts, and customer data.
Usage Example:
add_filter('wf_refund_invoice_payload_before_create', function($payload) {
$payload['amount'] = $payload['amount'] * 0.9; // Apply a 10% discount.
return $payload;
});
wf_refund_invoice_payment_before_create_or_update
Description:
Filters the payment data associated with a refund invoice before creation or update in Fortnox.
Variables:
$payment_data (array): Contains payment method, amount, and other payment-related information.
Usage Example:
add_filter('wf_refund_invoice_payment_before_create_or_update', function($payment_data) {
$payment_data['method'] = 'bank_transfer';
return $payment_data;
});
wf_invoice_refund_row_payload_before_create_or_update
Description:
Filters the data for each refund row in an invoice before it is created or updated in Fortnox.
Variables:
$row_data (array): Contains information about the refunded items, such as product IDs, quantities, and prices.
Usage Example:
add_filter('wf_invoice_refund_row_payload_before_create_or_update', function($row_data) {
// Adjust the refund quantity
$row_data['quantity'] = max(0, $row_data['quantity'] - 1);
// Decrease refund by 1 unit.
return $row_data;
});
wf_invoice_before_create_or_update
Description:
Filters the invoice data before it is created or updated in Fortnox.
Variables:
$invoice_data (array): Contains all details of the invoice, such as line items, totals, and customer information.
$order (WC_Order): The associated WooCommerce order object.
Usage Example:
add_filter('wf_invoice_before_create_or_update', function($invoice_data, $order) {
// Add a custom note to the invoice
$invoice_data['notes'][] = 'Processed by custom plugin.'; return $invoice_data;
}, 10, 2);
wf_invoice_payment_before_create_or_update
Description:
Filters the payment data associated with an invoice before creation or update in Fortnox.
Variables:
$payment_data (array): Contains payment details such as the payment method, amount, and transaction ID.
$order (WC_Order): The associated WooCommerce order object.
Usage Example:
add_filter('wf_invoice_payment_before_create_or_update', function($payment_data, $order) {
// Set a custom payment method for all invoices
$payment_data['method'] = 'credit_card';
return $payment_data;
}, 10, 2);
wf_order_number
Description:
Filters the order number used in the Fortnox integration.
Variables:
$order_number (string): The order number assigned by WooCommerce or customized by another filter.
$order (WC_Order): The WooCommerce order object.
Usage Example:
add_filter('wf_order_number', function($order_number, $order) {
return '111' . $order_number; // Prefix order numbers with FNX for Fortnox.
}, 10, 2);
wf_order_payload_before_create_or_update
Description:
Filters the order data before it is sent to Fortnox for creation or updating.
Variables:
$order_data (array): Contains all relevant details of the order, such as line items, shipping, and totals.
$order (WC_Order): The WooCommerce order object.
Usage Example:
add_filter('wf_order_payload_before_create_or_update', function($order_data, $order) {
// Add a custom field to the order payload
$order_data['custom_field'] = 'Custom Value'; return $order_data;
}, 10, 2);
wf_order_vat_included
Description:
Filters whether VAT is included in the order sent to Fortnox.
Variables:
$vat_included (bool): True if VAT is included, false if not.
$order (WC_Order): The WooCommerce order object.
Usage Example:
add_filter('wf_order_vat_included', function($vat_included, $order) {
return true;
// Ensure VAT is always included.
}, 10, 2);
wf_order_payload_before_send
Description:
Filters the final order payload just before it is sent to Fortnox.
Variables:
$order_payload (array): The complete order data that will be sent to Fortnox.
$order (WC_Order): The WooCommerce order object.
Usage Example:
add_filter('wf_order_payload_before_send', function($order_payload, $order) {
// Add a final modification to the order payload
$order_payload['final_check'] = true;
return $order_payload;
}, 10, 2);
wf_order_row_product
Description:
Filters the product data associated with an order row before it is included in the payload to Fortnox.
Variables:
$product_data (array): The product details such as name, SKU, and price.
$order_item (WC_Order_Item_Product): The WooCommerce order item object.
Usage Example:
add_filter('wf_order_row_product', function($product_data, $order_item) {
$product_data['name'] = strtoupper($product_data['name']);
return $product_data;
}, 10, 2);
wf_product_name
Description:
Filters the product name before it is used in an order row or elsewhere.
Variables:
$product_name (string): The product name.
$product_id (int): The ID of the product.
Usage Example:
add_filter('wf_product_name', function($product_name, $product_id) {
return $product_name . ' (Special Edition)';
}, 10, 2);
wf_order_row_payload_before_create_or_update
Description:
Filters the data for each order row before it is created or updated in Fortnox.
Variables:
$row_data (array): The order row data, including product details, quantities, and prices.
$order_item (WC_Order_Item_Product): The WooCommerce order item object.
Usage Example:
add_filter('wf_order_row_payload_before_create_or_update', function($row_data, $order_item) {
// Adjust quantity or pricing logic before sync
$row_data['quantity'] = $row_data['quantity'] * 2;
// Double the quantity for some reason.
return $row_data;
}, 10, 2);
wf_order_row_sales_account
Description:
Filters the sales account used for an order row.
Variables:
$sales_account (string): The sales account code.
$row_data (array): The order row data.
$order_item (WC_Order_Item_Product): The WooCommerce order item object.
Usage Example:
add_filter('wf_order_row_sales_account', function($sales_account, $row_data, $order_item) {
// Change sales account based on product category $product = wc_get_product($order_item->get_product_id());
if (in_array('special-category', $product->get_category_ids())) {
return 'SPECIAL_ACCOUNT';
}
return $sales_account;
}, 10, 3);
wf_order_shipping_account
Description:
Filters the shipping account used in an order.
Variables:
$shipping_account (string): The shipping account code.
$order (WC_Order): The WooCommerce order object.
Usage Example:
add_filter('wf_order_shipping_account', function($shipping_account, $order) {
// Set a specific shipping account for international orders
return ($order->get_shipping_country() !== 'SE') ? 'INTL_SHIPPING' : $shipping_account;
}, 10, 2);
wf_custom_shipping
Description:
Filters custom shipping data before it is included in the order payload sent to Fortnox.
Variables:
$shipping_data (array): The custom shipping data.
$order (WC_Order): The WooCommerce order object.
Usage Example:
add_filter('wf_custom_shipping', function($shipping_data, $order) {
// Add custom shipping details
$shipping_data['custom_field'] = 'Custom Value';
return $shipping_data;
}, 10, 2);
wf_order_way_of_delivery
Description:
Filters the way of delivery for an order before it is synced with Fortnox.
Variables:
$way_of_delivery (string): The method of delivery (e.g., 'home delivery', 'pickup').
$order (WC_Order): The WooCommerce order object.
Usage Example:
add_filter('wf_order_way_of_delivery', function($way_of_delivery, $order) {
// Override the way of delivery based on order value
return ($order->get_total() > 1000) ? 'premium_delivery' : $way_of_delivery;
}, 10, 2);
wf_order_terms_of_delivery
Description:
Filters the terms of delivery for an order before syncing with Fortnox.
Variables:
$terms_of_delivery (string): The terms of delivery (e.g., 'FOB', 'CIF').
$order (WC_Order): The WooCommerce order object.
Usage Example:
add_filter('wf_order_terms_of_delivery', function($terms_of_delivery, $order) {
// Set terms of delivery based on shipping country
return ($order->get_shipping_country() === 'US') ? 'FOB' : $terms_of_delivery;
}, 10, 2);