How To Check If User Purchased An Item On The Product Page

I managed to get the text to show "you bought this item", please how can i show the hink to the order in the product page?

Return $order_id in the function and use something like

{$purchaed_before=$product.product_id|my_purchased_before}
{if $purchased_before}
  

{$purchased_before nofilter}

{/if}

Return $order_id in the function and use something like

{$purchaed_before=$product.product_id|my_purchased_before}
{if $purchased_before}
  

{$purchased_before nofilter}

{/if}

I tried to return the order_id with the code generously provided by tbirnseth, return db_get_field("SELECT order_id FROM ?:orders AS o INNER JOIN ?:order_details AS od ON o.order_id=od.order_id AND od.product_id=?i WHERE o.user_id=?i ORDER BY order_id DESC", $product_id, $user_id); but it's causing an error

Return $order_id in the function and use something like

{$purchaed_before=$product.product_id|my_purchased_before}
{if $purchased_before}
  

{$purchased_before nofilter}

{/if}

Do you happen to have a suggestion on how to properly return the order id on the product page?

If you're using the code I provided and put it in a function, you just need to return $order_id and then use the return value.

If you're using the code I provided and put it in a function, you just need to return $order_id and then use the return value.

Yes, here's what i did but it's not working

function my_check_previous_order($product_id, $user_id) {
$product_id = $_REQUEST['product_id'];
$user_id = $_SESSION['auth']['user_id'];
if(empty($user_id) || empty($product_id)) { return false; }
return db_get_field("SELECT count(od.product_id) FROM ?:orders AS o LEFT JOIN ?:order_details AS od ON od.order_id=o.order_id AND od.product_id=?i WHERE o.user_id=?i", $product_id, $user_id);
//this is what's not working
return db_get_field("SELECT order_id FROM ?:orders AS o INNER JOIN ?:order_details AS od ON o.order_id=od.order_id AND od.product_id=?i WHERE o.user_id=?i ORDER BY order_id DESC", $product_id, $user_id);
}

If you are using a function with parameters of $product_id and $user_id, why are you setting them to global variables?

I have no idea of what you're truing to do based on the code you are providing. Also, please put code inside "code" tags so it's readable.

If you are using a function with parameters of $product_id and $user_id, why are you setting them to global variables?

I have no idea of what you're truing to do based on the code you are providing. Also, please put code inside "code" tags so it's readable.

yes, I'm trying to find out how to show the order url on the product page at the moment it's showing "you bought this item" but the link to the order is not working because the order id is not returned in the href

sorry, I've already freely provided all that I can in support of your endeavor.

Again, I strongly suggest you hire a developer to help you.

Does it mean there's no way to get the order id on the product page?

Does it mean there's no way to get the order id on the product page?

Of course, it is possible

Of course, it is possible

How can i do it please, that's the only thing hindering the href link from working.

<a href="{"orders.details?order_id=`$purchased_before_order_id`"|fn_url}">view the order details

how can i return this variable $purchased_before_order_id in the product page

Please check post #28