Code-Snippets-Functions/Execute a function on a child site/AffiliateWP/prevent-affiliatewp-from-awarding-commission-for-0-00-orders-in-woocommerce.txt
2020-07-30 15:26:44 -06:00

25 lines
735 B
Text

function am_affwp_woocommerce_block_referrals_for_zero_dollar_orders( $create_referral, $args ) {
// Return if WooCommerce isn't active.
if ( ! class_exists( 'WooCommerce' ) ) {
return $create_referral;
}
// Get the order ID from AffiliateWP.
$order_id = $args['reference'];
// Get the WooCommerce order based on the order ID.
$order = new WC_Order( $order_id );
// Get the order total.
$order_total = $order->get_total();
// Block referrals from being created if the WooCommerce order total is $0.00.
if ( '0.00' === $order_total ) {
$create_referral = false;
}
return $create_referral;
}
add_filter( 'affwp_integration_create_referral', 'am_affwp_woocommerce_block_referrals_for_zero_dollar_orders', 10, 2 );