Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param bool $result Whether the notification conditions have passed
- * @param \GeminiLabs\SiteReviews\Addon\Notifications\Notification $notification The Notification object
- *
- * @return bool - true if the notification should be sent, false otherwise.
- */
- add_filter('site-reviews-notifications/notification/is-valid', function ($result, $notification) {
- $uid = 'abcdef'; // Replace with the UID of the notification.
- if (!$result || $uid !== $notification->get('uid')) {
- return $result; // Conditions have already failed or wrong notification
- }
- $user = wp_get_current_user();
- if (!in_array('retail', $user->roles)) {
- return false; // Skip if user does not have the retail role
- }
- if (wc_get_customer_order_count($user->ID) > 1) {
- return true; // Skip if not the first order
- }
- if (!empty(get_user_meta($user->ID, '_coupon_email_sent', true))) {
- return false; // Skip if user has already been sent a coupon
- }
- update_user_meta($user->ID, '_coupon_email_sent', 1);
- return true; // Send notification
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement