The code below displays a message on the product page that has the "free" tag to the logged in user
function add_text_after_excerpt_single_product_free2( $short_description ) {
global $product;
$terms = get_the_terms( $product->get_id(), 'product_tag' );
foreach ( $terms as $term ) {
if ( $term->name == 'Free' && is_user_logged_in() ) {
$short_description .= 'Downloading this file is free and does not require subscription';
}
}
return $short_description;
}
add_filter('woocommerce_short_description','add_text_after_excerpt_single_product_free2', 20, 1);
I want the above code to be executed if a user has purchased a specific product
For example, a user buys a product called Photoshop training, and from now on the above code will be executed for him
thanx
2
Answers
You’d need to store the data in the user, and then access it via their login session. It looks to me like
Would do the trick. For reference:
https://developer.wordpress.org/reference/functions/add_user_meta/
https://wordpress.stackexchange.com/questions/111839/add-user-meta-vs-update-user-meta
You can write a custom function to check whether user buy a specific product. Try the below code. code will go in your active theme functions.php file.
This below function is inspired from here – Check if a user/guest has purchased specific products in WooCommerce
Tested and works