Как скрыть кнопку оформления заказа и показывать ее только для определенной категории c в Woocommerce?
Я хочу, чтобы клиенты видели корзину с добавленными товарами, но не хотели, чтобы они видели покупку и есть вариант покупки. Таким образом, только одна категория продуктов может иметь возможность оформления заказа. Каким может быть код для достижения этой цели?
Нашел эту оду в другой топи c, но не могу заставить ее работать.
add_action( 'woocommerce_check_cart_items', 'prevent_checkout_product_category_based' );
function prevent_checkout_product_category_based() {
// HERE set the product category slug
$category = 'uncategorised';
$found = $other = false; // Initializing variables
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item ) {
// checking for the specific product category
$term_slugs = wp_get_post_terms( $cart_item['product_id'], 'product_cat', array('fields' => 'slugs') );
if( in_array($category, $term_slugs) ) {
$found = true; // Targeted product category found
}
elseif( ! in_array($category, $term_slugs) && sizeof($term_slugs) > 0 ){
$other = true; // Other product categories found
}
}
// If the targeted product category is mixed with other product categories
if ( $found && $other ) {
// Display an error notice and avoid checkout
wc_add_notice( __( "The cart contains products from catalog and can't be mixed together, to allow checkout." ), 'error' );
}
}