geminilabs

[is_verified_owner]

Jan 6th, 2021 (edited)
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. /**
  2.  * Example usage: [is_verified_owner][site_reviews_form][/is_verified_owner]
  3.  *
  4.  * @param array $atts
  5.  * @param string $content
  6.  * @return string
  7.  */
  8. add_shortcode('is_verified_owner', function ($atts, $content = '') {
  9.     global $product;
  10.     if (!function_exists('wc_customer_bought_product') || empty($product)) {
  11.         return do_shortcode($content);
  12.     }
  13.     $isVerifiedOwner = wc_customer_bought_product('', get_current_user_id(), $product->get_id());
  14.     return $isVerifiedOwner || 'no' === get_option('woocommerce_review_rating_verification_required')
  15.         ? do_shortcode($content)
  16.         : esc_html__('Only logged in customers who have purchased this product may leave a review.', 'site-reviews-woocommerce');
  17. }, 10, 2);
Add Comment
Please, Sign In to add comment