This code snippet will prevent AffiliateWP from recording a commission for an affiliate, if the order total in WooCommerce is $0.00.


 * Prevent AffiliateWP from creating a referral if the order total in WooCommerce is $0.00.
 * @return bool $create_referral False if the referral cannot be created, true otherwise.
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 );

Why this snippet may be useful

Let’s say you offer a flat rate commission of $2.00. This means that each time a customer purchases via an affiliate’s link, the affiliate will receive $2.00 in commission.

If the order total is $0.00 (A free product being purchased, or perhaps a discount code was used), the affiliate will still be awarded $2.00. This may not be the behaviour you want.

You could enable the Ignore Referrals with Zero Amount option from AffiliatesSettingsMisc, but this will only ignore referrals that are generated at a $0.00 amount — not referrals based on WooCommerce’s order total.

Leave a Reply

Your email address will not be published. Required fields are marked *