Skip to content

Instantly share code, notes, and snippets.

@hedqvist
Last active June 30, 2023 12:10
Show Gist options
  • Save hedqvist/ac532fa0e6aaaa6bfc39e511f96aa617 to your computer and use it in GitHub Desktop.
Save hedqvist/ac532fa0e6aaaa6bfc39e511f96aa617 to your computer and use it in GitHub Desktop.
Fortnox - Custom price and discount
<?php
/**
* @snippet WooCommerce - Custom Price functions
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 6.0.0
*/
function redlight_fortnox_order_item_special_price( $orderItem, $item, $product_id, $order ) {
$product = wc_get_product($product_id);
$full_price_products = array('MIL-SATT-40KM','BOM-KOR'); // Out products that should be full price
if( !in_array( $product->get_sku(), $full_price_products ) ){
$orderItem['Price'] = $product->get_regular_price(); // Get the regular price of the product
$orderItem['DiscountType'] = 'PERCENT'; // PERCENT or AMOUNT
$orderItem['Discount'] = '48.5'; // Our Percentage
}
return $orderItem;
}
add_filter('obj_fortnox_order_item_row_data', 'redlight_fortnox_order_item_special_price', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment