Skip to content

Commit

Permalink
Added cart shipping class rule type.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Feb 5, 2024
1 parent 36c9266 commit 4534d86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/ShippingMethod/ShippingMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,24 @@ public function get_condition_types() {
'operators' => array( 'is', 'is_not' ),
'is_global' => true,
),
'shipping_classes' => array(
'label' => _x( 'Cart shipping class', 'shipments', 'woocommerce-germanized-shipments' ),
'fields' => array(
'classes' => array(
'type' => 'multiselect',
'data_type' => 'array',
'class' => 'wc-enhanced-select',
'label' => _x( 'Class', 'shipments', 'woocommerce-germanized-shipments' ),
'options' => function() {
return Package::get_shipping_classes();
},
),
),
'operators' => array( 'any_of', 'none_of' ),
'is_global' => true,
),
'package_shipping_classes' => array(
'label' => _x( 'Shipping Class', 'shipments', 'woocommerce-germanized-shipments' ),
'label' => _x( 'Package shipping class', 'shipments', 'woocommerce-germanized-shipments' ),
'fields' => array(
'classes' => array(
'type' => 'multiselect',
Expand Down Expand Up @@ -457,7 +473,7 @@ public function get_available_packaging_boxes( $package_data = array() ) {
}

/**
* Filter available packaging based on global rules, e.g. weight/total
* Filter available packaging based on global rules, e.g. weight/total/shipping classes
* and do only allow applicable packaging options to be chosen for actual packing process.
*/
if ( ! empty( $package_data ) && count( $global_rules ) > 0 ) {
Expand Down Expand Up @@ -807,7 +823,7 @@ protected function rule_applies( $rule, $package_data, $global_only = false ) {
$condition_applies = false;
}
}
} elseif ( 'package_shipping_classes' === $condition_type_name ) {
} elseif ( 'shipping_classes' === $condition_type || 'package_shipping_classes' === $condition_type_name ) {
$classes = isset( $condition['classes'] ) && ! empty( $condition['classes'] ) ? array_map( 'absint', (array) $condition['classes'] ) : array();

if ( array_intersect( $package_data[ $condition_type_name ], $classes ) ) {
Expand Down
1 change: 0 additions & 1 deletion src/ShippingProvider/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ public function set_tracking_desc_placeholder( $placeholder ) {
* @return string
*/
public function get_tracking_url( $shipment ) {

$tracking_url = '';
$tracking_id = $shipment->get_tracking_id();

Expand Down

0 comments on commit 4534d86

Please sign in to comment.