Plugin Directory

Changeset 2800084


Ignore:
Timestamp:
10/17/2022 02:45:17 PM (3 years ago)
Author:
shiptimizeplugins
Message:

incorrect way to check if contains class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • shiptimize-for-woocommerce/trunk/includes/admin/class-shiptimize-shipping.php

    r2800067 r2800084  
    783783
    784784          \$contains_classes_to_exclude = false;
    785           error_log(\$shipping_method->get_title());
     785          WooShiptimize::log(\$shipping_method->get_title());
    786786          // Check if the package contains products that have at least one of the selected classes
    787787          foreach ( \$package['contents'] as \$key => \$item ) {
    788             \$product = \$item['data']; 
    789 
     788             
    790789            foreach ( \$opt_exclude_classes  as \$c2exclude ) {
    791               if ( \$c2exclude > 0 ) {
    792                 \$contains_classes_to_exclude |= \$product->get_shipping_class_id(\$c2exclude) == \$c2exclude ;
     790              \$terms = get_the_terms( \$item['product_id'], 'product_shipping_class' );
     791              if ( \$terms ) {
     792                foreach(\$terms as \$term) {
     793                  \$contains_classes_to_exclude |=  \$term->term_id == \$c2exclude ; 
     794                }
    793795              }
    794796            }
    795797          }
    796798         
    797           error_log(\"contains class \" . ( \$contains_classes_to_exclude ? 1 : 0 ));
     799          WooShiptimize::log(\"contains class \" . ( \$contains_classes_to_exclude ? 1 : 0 ));
    798800
    799801          return !\$contains_classes_to_exclude;
     
    10451047            return \$available;
    10461048          }
    1047 
     1049 
    10481050          \$contains_classes_to_exclude = false;
    1049           error_log(\$shipping_method->get_title());
     1051          WooShiptimize::log(\$shipping_method->get_title());
    10501052          // Check if the package contains products that have at least one of the selected classes
    10511053          foreach ( \$package['contents'] as \$key => \$item ) {
    1052             \$product = \$item['data']; 
    1053 
     1054             
    10541055            foreach ( \$opt_exclude_classes  as \$c2exclude ) {
    1055               if ( \$c2exclude > 0 ) {
    1056                 \$contains_classes_to_exclude |= \$product->get_shipping_class_id(\$c2exclude) == \$c2exclude ;
     1056              \$terms = get_the_terms( \$item['product_id'], 'product_shipping_class' );
     1057              if ( \$terms ) {
     1058                foreach(\$terms as \$term) {
     1059                  \$contains_classes_to_exclude |=  \$term->term_id == \$c2exclude ; 
     1060                }
    10571061              }
    10581062            }
    10591063          }
    10601064         
    1061           error_log(\"contains class \" . ( \$contains_classes_to_exclude ? 1 : 0 ));
     1065          WooShiptimize::log(\"contains class \" . ( \$contains_classes_to_exclude ? 1 : 0 ));
    10621066
    10631067          return !\$contains_classes_to_exclude;
Note: See TracChangeset for help on using the changeset viewer.