<?php

/**
 * Hides the Easy Digital Downloads discount field at checkout if the customer is referred by an affiliate.
 *
 * @link https://andrew.dev/snippets/hide-easy-digital-downloads-discount-field-if-customer-referred-by-affiliate/
 */
function am_affwp_edd_hide_discount_field_if_referred() {

	// Bail if AffiliateWP is not active.
	if ( ! function_exists( 'affiliate_wp' ) ) {
		return;
	}

	// Customer was referred by an affiliate.
	if ( affiliate_wp()->tracking->was_referred() ) {
		// Unhook the discount field at checkout.
		remove_action( 'edd_checkout_form_top', 'edd_discount_field', -1 );
	}

}
add_action( 'template_redirect', 'am_affwp_edd_hide_discount_field_if_referred' );

Leave a Reply

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