/*Change "Proceed to Checkout button link" for a specific category in the cart*/
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 ) {
$product = $cart_item['data'];
// If Cart has category "tradeline", set $cat_in_cart to true
if ( has_term( 'gift-cards', 'product_cat', $product->get_id() ) ) {
$cat_in_cart = true;
break;
}
}
// Do something if category "Gift Cards" is in the Cart
if ( $cat_in_cart ) {
// For example, print a notice
add_filter('woocommerce_get_checkout_url', 'dj_redirect_checkout');
function dj_redirect_checkout($url) {
global $woocommerce;
if(is_cart()){
$checkout_url = 'https://adventureclues.com/checkout-gift';
}
else {
//other url or leave it blank.
}
return $checkout_url;
}
}
}