Skip to main content

Check if User Has Already Purchased Product in woo-commerce?


WooCommerce: Check if User Has Already Purchased Product



function start_deal_button(){
ob_start();
global $user;


global $product;
$current_user = wp_get_current_user();

if(!is_user_logged_in())
{
echo "<a href='".site_url().'/my-account'."' class='start-deal-button'>Start Deal  <i class='fa fa-handshake'></i></a>";
}

if((has_active_subscription() || wc_customer_bought_product( $current_user->user_email, $current_user->ID,'9011')) && (is_user_logged_in())){ 
    echo "<a href='".site_url().'/start-deal'."' class='start-deal-button'>Start Deal  <i class='fa fa-handshake'></i></a>";;
}

if(!(has_active_subscription() || wc_customer_bought_product( $current_user->user_email, $current_user->ID,'9011')) && (is_user_logged_in())){
    echo "<a href='".site_url().'/pricing/'."' class='start-deal-button'>Start Deal  <i class='fa fa-handshake'></i></a>";

}

$obc = ob_get_contents();
ob_end_clean();
return $obc;
}
add_shortcode("startdeal","start_deal_button");

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...