1. Customize
  2. WooCommerce Integration
  3. Exclude products from “New product purchase” event

Exclude products from “New product purchase” event

The following snippet shows how to force some products to not trigger the “New product purchase” event.

function my_prefix_exclude_products_for_new_product_purchase_event( $return = false, $user_id = 0, $requirement_id = 0, $trigger = '', $site_id = 0, $args = array() ) {

    // Check if this is the event we are looking for
    if( $return && $trigger === 'gamipress_wc_new_product_purchase' ) {

        $product_id = $args[0];

        // If this is the product we want to exclude, then don't award to the user this
        if( $product_id === 123 ) {
            return false;
        }

    }

    // Send back our eligibility
    return $return;
}
add_filter( 'user_has_access_to_achievement', 'my_prefix_exclude_products_for_new_product_purchase_event', 10, 6 );
Was this article helpful to you? Yes 1 No

How can we help?