Guest User

Untitled

a guest
Dec 1st, 2015
201
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // New
  2. public function patricks_enable_free_shipping( $is_available ) {
  3.  
  4. global $woocommerce;
  5. $IsEligibleONE = False;
  6. $IsEligibleALL = False;
  7. $eligibleCount = 0;
  8. $Count = 0;
  9. // set the shipping classes that are eligible
  10. $eligibleALL = array( 'free-shipping-all' );
  11. $eligibleONE = array( 'free-shipping' );
  12.  
  13. // get cart contents
  14. $cart_items = $woocommerce->cart->get_cart();
  15.  
  16. // loop through the items checking to make sure they all have the right class
  17. foreach ( $cart_items as $key => $item ) {
  18.     $Count = $Count + 1;
  19. //echo “[Loop ” . $count;
  20.  
  21.     if ( ! in_array( $item['data']->get_shipping_class(), $eligibleONE ) ) {
  22.     echo "Not Eligible ONE -";
  23.         if ( ! in_array( $item['data']->get_shipping_class(), $eligibleALL ) ) {
  24.         //  echo “Not Eligible ALL]”;
  25.         }
  26.         else {
  27.         $IsEligibleALL = True;
  28.         $eligibleCount = $eligibleCount + 1;
  29.         //  echo “Eligible ALL: Count ” . $eligibleCount . “]”;
  30.         }
  31.     }  
  32.     //Is eligible for single-item Free Shipping
  33.     else {
  34.         $eligibleCount = $eligibleCount + 1;
  35.         $IsEligibleONE = True;
  36.         //  echo “Eligible ONE: Count ” . $eligibleCount . “]”;
  37.     }
  38. }
  39. if ($eligibleCount == 0 ) {
  40.     //echo “ENTIRE CART NOT ELIGIBLE–“;
  41.     //echo “Eligible Count:” . $eligibleCount ;
  42.     return false;
  43. }
  44.  
  45. If ($IsEligibleALL == True) {
  46.     //echo “END ALL–Eligible for ALL Count:” . $eligibleCount ;
  47.     return $is_available;
  48. }
  49. elseIf ($IsEligibleONE == True && $Count == 1) {
  50.     //echo “END ONE–Eligible for Single Count:” . $eligibleCount ;
  51.     return $is_available;
  52. }
  53. else {
  54.     //echo “END ONE–Single Not Eligible Since Count > 1 : Count” . $Count ;
  55.     return false;
  56. }
  57. }
RAW Paste Data