function my_order_item_name( $item_name, $item ) {
$product = wc_get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
$link = get_permalink( $product->get_id() );
return '<a href="'. $link .'" rel="nofollow">'. $item_name .'</a>';
}
add_filter( 'woocommerce_order_item_name', 'my_order_item_name', 10, 2 );
Thread Starter
pjhoo5
(@pjhoo5)
@crslz
Thanks for the answer.
But after applying it to the code snippets, I get the following error:
Fatal error: Uncaught Error: Call to a member function get_id() on bool in….
Can you solve it?
Thank you 🙂
Okay, can you try it this way?
function my_order_item_name( $item_name, $item ) {
$product = wc_get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
$link = get_permalink( $product['id'] );
return '<a href="'. $link .'" rel="nofollow">'. $item_name .'</a>';
}
add_filter( 'woocommerce_order_item_name', 'my_order_item_name', 10, 2 );
If that also does not work, then execute the following code and post the output here
function my_order_item_name( $item_name, $item ) {
$product = wc_get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
$type = gettype($product) . '<br>';
return $type . $product;
}
add_filter( 'woocommerce_order_item_name', 'my_order_item_name', 10, 2 );
Thread Starter
pjhoo5
(@pjhoo5)
@crslz
Thanks for the answer.
It works exactly fine.
However, the product title is a course from learnpress.
I’m using Learnpres-woocommerce integration.
When a customer purchases a course through wooCommerce, they will receive an woocommerce template email.
In summary, when you click on a course title in the woocommerce customer order complete email, you should go to that course page.
@pjhoo5 well, as you can see in my code example the product url is used (get permalink). So this can easily be adjusted to a different url.
Because you probably do not want you to hardcode this URL for every product, it may be useful that you can link this URL to the product, for example with the product options (create/change product). However, this requires additional custom code.