@david
The order currency is stored natively by WooCommerce, even when our product is not used. It’s true that, in basic WooCommerce, the order currency, when the order is placed, always matches the base currency, but that’s more of a coincidence than an ideal logic. This integration plugin should always take the order currency, and it can be done easily by using standard WooCommerce calls (see below).
Fix for the currency issue
Modify method Affiliates_WooCommerce_Light_Integration::woocommerce_checkout_order_processed() to take the order currency, as follows.
Original code
public static function woocommerce_checkout_order_processed( $order_id ) {
$order_total = get_post_meta( $order_id, '_order_total', true );
$order_tax = get_post_meta( $order_id, '_order_tax', true );
$order_shipping = get_post_meta( $order_id, '_order_shipping', true );
$order_shipping_tax = get_post_meta( $order_id, '_order_shipping_tax', true );
$order_subtotal = $order_total - $order_tax - $order_shipping - $order_shipping_tax;
$currency = get_option( 'woocommerce_currency' );
Fixed code
public static function woocommerce_checkout_order_processed( $order_id ) {
$order = new WC_Order( $order_id );
$order_total = get_post_meta( $order_id, '_order_total', true );
$order_tax = get_post_meta( $order_id, '_order_tax', true );
$order_shipping = get_post_meta( $order_id, '_order_shipping', true );
$order_shipping_tax = get_post_meta( $order_id, '_order_shipping_tax', true );
$order_subtotal = $order_total - $order_tax - $order_shipping - $order_shipping_tax;
// Get the currency from the order, rather than the base one
$currency = $order->get_order_currency();
One more suggestion
I would recommend not to use get_post_meta() to retrieve orders’ attributes. Class WC_Order includes many convenience methods that allow to access the data, and they evolve with WooCommerce. Should the WooCommerce Core developers decide to change the keys of the order meta, the get_post_meta() calls would fail, while the WC_Order methods would keep working, as they would reflect the changes.
hi Diego! i need get the subtotal
<?php echo $order->get_subtotal();?> dont work for me
@martindi1 I’m not the author of this plugin, I don’t provide support for it. I was just sending a suggestion to the author.
I would recommend opening a new support request: https://ww.wp.xz.cn/support/plugin/affiliates-woocommerce-light