Last active
December 1, 2020 23:12
-
-
Save tobychung/c2f5bb4525917cea7b172610cb7da4e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function match( $match, $operator, $value ) { | |
$value = $this->get_value( $value ); | |
if ( '==' == $operator ) : | |
// Promotion: If cart match the category and greater than two then shipping free | |
$count = 0; | |
foreach ( WC()->cart->get_cart() as $product ) : | |
if ( has_term( $value, 'product_cat', $product['product_id'] )) : | |
$count = $count + $product['quantity']; | |
return ($count >= 2) ? true : false; | |
endif; | |
endforeach; | |
// Backup: If any item in cart matched the category then shipping free | |
// foreach ( WC()->cart->get_cart() as $product ) : | |
// if ( has_term( $value, 'product_cat', $product['product_id'] ) ) : | |
// return true; | |
// endif; | |
// endforeach; | |
elseif ( '!=' == $operator ) : | |
$match = true; | |
foreach ( WC()->cart->get_cart() as $product ) : | |
if ( has_term( $value, 'product_cat', $product['product_id'] ) ) : | |
return false; | |
endif; | |
endforeach; | |
endif; | |
return $match; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment