Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // New
- public function patricks_enable_free_shipping( $is_available ) {
- global $woocommerce;
- $IsEligibleONE = False;
- $IsEligibleALL = False;
- $eligibleCount = 0;
- $Count = 0;
- // set the shipping classes that are eligible
- $eligibleALL = array( 'free-shipping-all' );
- $eligibleONE = array( 'free-shipping' );
- // get cart contents
- $cart_items = $woocommerce->cart->get_cart();
- // loop through the items checking to make sure they all have the right class
- foreach ( $cart_items as $key => $item ) {
- $Count = $Count + 1;
- //echo “[Loop ” . $count;
- if ( ! in_array( $item['data']->get_shipping_class(), $eligibleONE ) ) {
- echo "Not Eligible ONE -";
- if ( ! in_array( $item['data']->get_shipping_class(), $eligibleALL ) ) {
- // echo “Not Eligible ALL]”;
- }
- else {
- $IsEligibleALL = True;
- $eligibleCount = $eligibleCount + 1;
- // echo “Eligible ALL: Count ” . $eligibleCount . “]”;
- }
- }
- //Is eligible for single-item Free Shipping
- else {
- $eligibleCount = $eligibleCount + 1;
- $IsEligibleONE = True;
- // echo “Eligible ONE: Count ” . $eligibleCount . “]”;
- }
- }
- if ($eligibleCount == 0 ) {
- //echo “ENTIRE CART NOT ELIGIBLE–“;
- //echo “Eligible Count:” . $eligibleCount ;
- return false;
- }
- If ($IsEligibleALL == True) {
- //echo “END ALL–Eligible for ALL Count:” . $eligibleCount ;
- return $is_available;
- }
- elseIf ($IsEligibleONE == True && $Count == 1) {
- //echo “END ONE–Eligible for Single Count:” . $eligibleCount ;
- return $is_available;
- }
- else {
- //echo “END ONE–Single Not Eligible Since Count > 1 : Count” . $Count ;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement