Noptin_WooCommerce_Lifetime_Value_Trigger::is_rule_valid_for_args( $rule,  $args,  $subscriber,  $action )


Source Source

File: includes/automation-rules/triggers/class-noptin-woocommerce-lifetime-value-trigger.php

    public function is_rule_valid_for_args( $rule, $args, $subscriber, $action ) {
        $settings = $rule->trigger_settings;

        // Ensure that we have a value.
        if ( empty( $settings['lifetime_value'] ) ) {
            return false;
        }

        // Fetch the user associated with the order.
        $user = $this->bridge->get_order_customer_user_id( $args['order_id'] );
        if ( empty( $user ) ) {
            $user = $this->bridge->get_order_customer_email( $args['order_id'] );
        }

        // Get the user's lifetime value.
        $user_value   = $this->bridge->get_total_spent( $user );
        $needed_value = (float) $settings['lifetime_value'];

        // Does the user meet the required lifetime value.
        if ( $user_value < $needed_value ) {
            return false;
        }

        // Ensure that the user reached this milestone in this specific order.
        $previous_total = $user_value - (float) $args['total'];

        return $previous_total < $needed_value;

    }

Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation