Advertisement
geminilabs

Untitled

Mar 16th, 2025
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. /**
  2.  * @param bool $result  Whether the notification conditions have passed
  3.  * @param \GeminiLabs\SiteReviews\Addon\Notifications\Notification $notification  The Notification object
  4.  *
  5.  * @return bool - true if the notification should be sent, false otherwise.
  6.  */
  7. add_filter('site-reviews-notifications/notification/is-valid', function ($result, $notification) {
  8.     $uid = 'abcdef'; // Replace with the UID of the notification.
  9.     if (!$result || $uid !== $notification->get('uid')) {
  10.         return $result; // Conditions have already failed or wrong notification
  11.     }
  12.     $user = wp_get_current_user();
  13.     if (!in_array('retail', $user->roles)) {
  14.         return false; // Skip if user does not have the retail role
  15.     }
  16.     if (wc_get_customer_order_count($user->ID) > 1) {
  17.         return true; // Skip if not the first order
  18.     }
  19.     if (!empty(get_user_meta($user->ID, '_coupon_email_sent', true))) {
  20.         return false; // Skip if user has already been sent a coupon
  21.     }
  22.     update_user_meta($user->ID, '_coupon_email_sent', 1);
  23.     return true; // Send notification
  24. }, 10, 2);
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement