Created
July 17, 2024 07:03
-
-
Save braddalton/1a54b86781b40f830cc2475627f09d3a to your computer and use it in GitHub Desktop.
How To Add Category Name To Order Details in WooCommerce
This file contains 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_order_item_meta_end', 'display_custom_data_in_emails', 10, 4 ); | |
function display_custom_data_in_emails( $item_id, $item, $order, $bool ) { | |
$terms = wp_get_post_terms( $item->get_product_id(), 'product_cat', array( 'fields' => 'names' ) ); | |
echo "<br><small>" . implode(', ', $terms) . "</small>"; | |
} | |
add_action( 'woocommerce_after_order_itemmeta', 'custom_admin_order_itemmeta', 15, 3 ); | |
function custom_admin_order_itemmeta( $item_id, $item, $product ){ | |
if ( ! is_admin() ) return; | |
if ( $item->is_type( 'line_item' ) ){ | |
$terms = wp_get_post_terms( $item->get_product_id(), 'product_cat', array( 'fields' => 'names' ) ); | |
echo "<br><small>" . implode(', ', $terms) . "</small>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment