У меня есть фрагмент, полученный от https://businessbloomer.com/woocommerce-check-product-category-cart/, который:
/*
* @snippet Check if Product Category is in the Cart - WooCommerce
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=72900
* @author Rodolfo Melogli
* @testedwith WooCommerce 3.1.2
*/
add_action('woocommerce_before_cart', 'bbloomer_check_category_in_cart');
function bbloomer_check_category_in_cart() {
// Set $cat_in_cart to false
$cat_in_cart = false;
// Loop through all products in the Cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// If Cart has category "download", set $cat_in_cart to true
if ( has_term( 'download', 'product_cat', $cart_item['product_id'] ) ) {
$cat_in_cart = true;
break;
}
}
// Do something if category "download" is in the Cart
if ( $cat_in_cart ) {
// For example, print a notice
wc_print_notice( 'Category Downloads is in the Cart!', 'notice' );
// Or maybe run your own function...
// ..........
}
}
```
It displays a notice if a product category is in the cart but it display the message via ```wc_print_notice``` on the cart page. I would like to display this message on a custom theme page template either via a short-code or any suggestions are welcome. T.I.A