Skip to content

Instantly share code, notes, and snippets.

@o-nkar
Last active February 12, 2021 10:45
Show Gist options
  • Save o-nkar/c6fd0221e7de07414f35a6cf34792068 to your computer and use it in GitHub Desktop.
Save o-nkar/c6fd0221e7de07414f35a6cf34792068 to your computer and use it in GitHub Desktop.
<?php
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$totalquantity = 0;
$category_found = 0;
foreach($items as $item => $values) {
$id = $values['data']->get_id();
$_product = wc_get_product( $id );
$totalquantity += $values['quantity'];
if( has_term( '===category name to check goes here===', 'product_cat', $id ) ){
$category_found = 1;
}
}
if( $totalquantity ==0 ){
return;
}
$link = '';
if( $category_found ){
// new set of link if category found into above cart items
switch ($totalquantity) {
case 2:
$link = 'https://mytap.com.au/60min-service-book-now/';
break;
case 3:
$link = 'https://mytap.com.au/90min-service-book-now/';
break;
case 4:
$link = 'https://mytap.com.au/120min-service-book-now/';
break;
case 5:
$link = 'https://mytap.com.au/150min-service-book-now/';
break;
default:
$link = 'lhttps://mytap.com.au/30min-service-book-now/';
break;
case in_array($totalquantity, range(6,20)): //the range from range of 6-20
$link = 'https://mytap.com.au/over-5-manual-booking/';
break;
}
}else{
// old set of condition if no category found
switch ($totalquantity) {
case 2:
$link = 'https://mytap.com.au/60min-service-book-now/';
break;
case 3:
$link = 'https://mytap.com.au/90min-service-book-now/';
break;
case 4:
$link = 'https://mytap.com.au/120min-service-book-now/';
break;
case 5:
$link = 'https://mytap.com.au/150min-service-book-now/';
break;
default:
$link = 'lhttps://mytap.com.au/30min-service-book-now/';
break;
case in_array($totalquantity, range(6,20)): //the range from range of 6-20
$link = 'https://mytap.com.au/over-5-manual-booking/';
break;
}
}
if( !empty($link )){
echo "<a href='".$link."' >BOOK NOW</a>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment