I am working on an if statement that determines whether the user is logged in and whether they have purchased the product already.
I have found the following code determines this correctly:
<?php
if ( is_user_logged_in() ) {
global $product;
$current_user = wp_get_current_user();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->get_id() )):
?>
However I wish to adjust this so that I can display separate content when the user is logged in.
I have spent some hours trying to incorporate the above code into a traditional loop but have been unsuccessful.
The following works:
<?php if ( is_user_logged_in() ): ?>
<h1>Logged In</h1>
<?php else: ?>
<h1>Logged Out</h1>
<?php endif ?>
But when I add the markup to determine if the product has been purchased, I recieve errors. Can anyone help?
Aucun commentaire:
Enregistrer un commentaire