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
CodePudding user response:
You'd need to store the data in the user, and then access it via their login session. It looks to me like
add_user_meta( int $user_id, string $meta_key, mixed $meta_value, bool $unique = false )
Would do the trick. For reference: