'Display a custom taxonomy in WooCommerce cart, checkout, and emails
I have added a custom taxonomy to my WooCommerce site via the CPT UI plugin. The taxonomy slug is 'leadtime', and in it I add a lead time to a product. Examples of lead times are: "3 Weeks"; "2 Weeks"; or "Now available".
With the help of this SO answer I have been able to show the taxonomy on a single product page, and also on an archive page.
However, I have not managed to show the taxonomy in the meta field on the cart and checkout pages. I would also like to show the lead time in the pdf invoice, for which I use the WooCommerce PDF Invoices & Packing Slips plugin by WP-Overnight.
===
What I have tried so far:
Without success, I tried to use the same code to retrieve the leadtime value, and use a cart-appropriate hook.
function custom_leadtime_in_cart_meta() {
global $product;
$taxonomy = 'leadtime'; // <== Here set your custom taxonomy
if( ! taxonomy_exists( $taxonomy ) )
return; // exit
$term_ids = wp_get_post_terms( $product->get_id(), $taxonomy, array('fields' => 'ids') );
if ( ! empty($term_ids) ) {
echo get_the_term_list( $product->get_id(), 'leadtime', '<span class="custom_taxonomy_leadtime_archive">' . _n( 'Lead time:', 'Lead times:', count( $term_ids ), 'woocommerce' ) . ' ', ', ', '</span>' );
};
}
add_filter( 'woocommerce_add_cart_item_data', 'custom_leadtime_in_cart_meta', 10, 3 );
Your help will be most welcome!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
