In WooCommerce, the product links in order details currently lead to the product edit page instead of the product page in the webshop. I tried adding some code to fix this and using
$product_link = $product ? get_permalink( $product->get_id() ) : '';
but it doesn’t work and it also duplicates the product title on the order details form.
Related question:
Change product url in woocommerce order detail
add_action( 'woocommerce_before_order_itemmeta', 'custom_order_item_product_link', 10, 3 );
function custom_order_item_product_link( $item_id, $item, $product ) {
if ( ! is_a( $product, 'WC_Product' ) ) {
return;
}
$product_link = $product->is_visible() ? $product->get_permalink() : '';
if ( $product_link ) {
printf( '<a href="%s">%s</a>', esc_url( $product_link ), esc_html( $product->get_name() ) );
} else {
echo esc_html( $product->get_name() );
}
}
2
Answers
This is your best option due to lack of hooks / filters in order items.
Add the following function in your active theme functions.php
Each order item will look like :
Product name - Preview link
.Still your product name will be wrapped in edit link but Preview link will lead to front product page.
As the product link in admin order edit pages is not editable/filterable via any hooks or templates, you need something a bit different using JavaScript, to be able to change this admin product link to the frontend product permalink.
Try the following instead (works also with HPOS):
Code goes on functions.php file of your child theme (or in a plugin). Tested and works.