Created
July 6, 2024 17:47
-
-
Save shameemreza/f45f4d448420ec2c8f48733226687d94 to your computer and use it in GitHub Desktop.
Change the order items admin product link to the product permalink frontend in WooCommerce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_before_order_itemmeta', 'add_admin_order_item_product_permalink', 10, 2 ); | |
function add_admin_order_item_product_permalink( $item_id, $item ) { | |
if( $item->get_type() !== 'line_item' ) | |
return; | |
$product = $item->get_product(); | |
// Add a hidden input field with the product permalink | |
printf( '<input type="hidden" name="product-permalink" value="%s">', esc_url($product->get_permalink())); | |
} | |
// Change order items admin product link to the product frontend permalink | |
add_filter( 'admin_footer', 'admin_order_items_with_product_permalink_js' ); | |
function admin_order_items_with_product_permalink_js() { | |
global $pagenow, $typenow; | |
if ( ( $pagenow === 'post.php' && $typenow === 'shop_order' ) | |
|| ( $pagenow === 'admin.php' && isset($_GET['page']) && isset($_GET['action']) | |
&& $_GET['page'] === 'wc-orders' && $_GET['action'] === 'edit' ) ) : | |
?> | |
<script> | |
jQuery('#order_line_items tr').each(function(){ | |
jQuery(this).find('td.name a').prop('href', jQuery(this).find('input[name=product-permalink]').val()); | |
}); | |
</script> | |
<?php | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment