Plugin Directory

Changeset 2800481


Ignore:
Timestamp:
10/18/2022 09:28:54 AM (3 years ago)
Author:
shiptimizeplugins
Message:

missing use case, the only free methods that match are invalid for cart then no methods will display

Location:
shiptimize-for-woocommerce/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • shiptimize-for-woocommerce/trunk/constants.php

    r2800002 r2800481  
    44define( 'SHIPTIMIZE_API_URL', 'https://api.pakketmail.nl/v3' );
    55define( 'SHIPTIMIZE_BRAND', 'Shiptimize' );
    6 define( 'SHIPTIMIZE_VERSION', '3.1.54' );
     6define( 'SHIPTIMIZE_VERSION', '3.1.56' );
    77define( 'SHIPTIMIZE_CREATE_ACCOUNT', 'https://www.shiptimize.me/quote/' );
    88define( 'SHIPTIMIZE_CHECKOUT', 0);
  • shiptimize-for-woocommerce/trunk/includes/class-woo-shiptimize.php

    r2800116 r2800481  
    303303
    304304  /**
     305   * Checks exclude classes if defined to determine if the rate is valid
     306   **/
     307  public function is_rate_valid( $r , $package ) {
     308    $options = get_option( 'woocommerce_' . $r->method_id . '_' . $r->instance_id . '_settings' );
     309
     310    if( isset( $options['excludeclasses'] ) && $options['excludeclasses'] ) {
     311      WooShiptimize::log( $r->label );
     312      $opt_exclude_classes = explode( ',', $options['excludeclasses'] );
     313      $contains_classes_to_exclude = false;
     314   
     315      // Check if the package contains products that have at least one of the selected classes
     316      foreach ( $package['contents'] as $key => $item ) {
     317        foreach ( $opt_exclude_classes  as $c2exclude ) {
     318          $terms = get_the_terms( $item['product_id'], 'product_shipping_class' );
     319          if ( $terms ) {
     320            foreach( $terms as $term ) {
     321              $contains_classes_to_exclude |=  $term->term_id == $c2exclude ; 
     322            }
     323          }
     324        }
     325      } 
     326
     327      WooShiptimize::log("contains class " . ( $contains_classes_to_exclude ? 1 : 0 ));
     328      return !$contains_classes_to_exclude; 
     329    }
     330
     331    return true;
     332  }
     333
     334  /**
    305335   * Allow users to choose, if free shipping, then hide anything not free
    306336   * Also check if exclude classes is set inside the shipping method
    307337   **/
    308338  public function rates_filter ( $rates, $package ) {
     339
    309340    // Check if hide not free enabled
    310341    if ( get_option('shiptimize_hide_not_free') ) {
    311342      $free = array();
    312       foreach ( $rates as $id => $r) {
    313        
    314         if ($r->cost == 0) {
     343      foreach ( $rates as $id => $r) {
     344        if ( $r->cost == 0 && $this->is_rate_valid( $r, $package ) ) {
    315345          array_push($free, $r);
    316346        }
    317347      }
    318348
    319       if ( !empty($free) ) {
     349      if ( !empty( $free ) ) {
    320350        $rates = $free;
    321351      } 
    322352    }
    323353
    324     /// Check for exclude classes
     354    // Check for exclude classes
    325355    $newrates = array();
    326356    foreach ( $rates as $id => $r) {
    327       $options = get_option('woocommerce_' . $r->method_id . '_' . $r->instance_id . '_settings');
    328    
    329       if(isset($options['excludeclasses']) && $options['excludeclasses']) {
    330         WooShiptimize::log($r->label);
    331 
    332         $opt_exclude_classes = explode( ',', $options['excludeclasses']);
    333         $contains_classes_to_exclude = false;
    334      
    335         // Check if the package contains products that have at least one of the selected classes
    336         foreach ( $package['contents'] as $key => $item ) {
    337           foreach ( $opt_exclude_classes  as $c2exclude ) {
    338             $terms = get_the_terms( $item['product_id'], 'product_shipping_class' );
    339             if ( $terms ) {
    340               foreach($terms as $term) {
    341                 $contains_classes_to_exclude |=  $term->term_id == $c2exclude ; 
    342               }
    343             }
    344           }
    345         } 
    346 
    347         WooShiptimize::log("contains class " . ( $contains_classes_to_exclude ? 1 : 0 ));
    348         if ( !$contains_classes_to_exclude ) {
    349           array_push($newrates,$r);
    350         }
    351       }
    352       else {
    353         array_push($newrates, $r);
    354       }
    355 
    356       $rates = $newrates;
    357     }
    358 
    359     return $rates;
     357      if( $this->is_rate_valid($r, $package) ) {
     358        array_push( $newrates,$r );
     359      }
     360    }
     361       
     362    return $newrates;
    360363  }
    361364
  • shiptimize-for-woocommerce/trunk/readme.txt

    r2800067 r2800481  
    5959== Changelog ==
    6060
     61= 3.1.56 - 2022-10-18 =
     62* fix - If hide shipping methods was enabled and only rates that can't display because of class constraints match, then no rates would not display.
     63
    6164= 3.1.55 - 2022-10-17 =
    6265* enhancement - If plugin Advanced Shipping is installed and active allow sellers to specify certain classes where our shipping methods will not display at checkout.
  • shiptimize-for-woocommerce/trunk/shiptimize.php

    r2800059 r2800481  
    33 * Plugin Name: Shiptimize for WooCommerce
    44 * Description: Shiptimize for WooCommerce 
    5  * Version: 3.1.55
     5 * Version: 3.1.56
    66 * Author: Shiptimize
    77 * Author URI: https://shiptimize.me
Note: See TracChangeset for help on using the changeset viewer.