Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions includes/abstracts/class-sst-abstract-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -943,25 +943,40 @@ abstract protected function handle_error( $message );
* @return float Calculated excise tax.
*/
protected function calculate_excise_tax( $items, $state ) {
if ( 'CO' !== $state || current_time( 'Ymd' ) < 20250401 ) {
$is_colorado_order = 'CO' === strtoupper( $state );

if ( ! $is_colorado_order || current_time( 'Ymd' ) < 20250401 ) {
return 0;
}

if ( ! is_null( $this->get_certificate() ) ) {
return 0;
}

$excise_tax = 0;
$excise_tax = 0;
$has_gun_or_ammo_tic_item = false;

foreach ( $items as $item ) {
$product_id = $item['product_id'] ?? 0;
$variation_id = $item['variation_id'] ?? 0;

if ( ! $product_id ) continue;

if ( ! $product_id ) {
continue;
}

$tic = SST_Product::get_tic( $product_id, $variation_id );

if ( in_array( (int)$tic, array( 90505, 90506 ) ) ) {
$line_total = $item['line_total'] ?? 0;
$excise_tax += $line_total * 0.065;
if ( SST_Product::is_gun_or_ammo_tic( $tic ) ) {
$has_gun_or_ammo_tic_item = true;
$line_total = $item['line_total'] ?? 0;
$excise_tax += $line_total * 0.065;
}
}

if ( ! $has_gun_or_ammo_tic_item ) {
return 0;
}

return $excise_tax;
}

Expand Down
30 changes: 23 additions & 7 deletions includes/class-sst-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,37 @@ public function create_packages() {
$packages = array_merge( $packages, $this->split_package( $raw_package ) );
}

// Add fees to first package.
if ( apply_filters( 'wootax_add_fees', true ) ) {
$fees = array();

// Add fees to packages.
if ( ! empty( $packages ) && apply_filters( 'wootax_add_fees', true ) ) {
foreach ( $this->order->get_fees() as $item_id => $fee ) {
$name = empty( $fee['name'] ) ? __( 'Fee', 'simple-sales-tax' ) : $fee['name'];
$fee_id = sanitize_title( $name );

$fees[ $item_id ] = (object) array(
$fee_obj = (object) array(
'id' => $fee_id,
'amount' => $fee['line_total'],
);
}

$packages[ key( $packages ) ]['fees'] = $fees;
$target_package_key = key( $packages );

if ( $fee_id === 'co-excise-tax' || 'CO EXCISE TAX' === strtoupper( $name ) ) {
foreach ( $packages as $pkg_key => $pkg ) {
foreach ( $pkg['contents'] as $content ) {
$tic = SST_Product::get_tic( $content['product_id'], $content['variation_id'] );
if ( SST_Product::is_gun_or_ammo_tic( $tic ) ) {
$target_package_key = $pkg_key;
break 2;
}
}
}
}

if ( ! isset( $packages[ $target_package_key ] ) ) {
$target_package_key = key( $packages );
}

$packages[ $target_package_key ]['fees'][ $item_id ] = $fee_obj;
}
}

// Logging
Expand Down
12 changes: 12 additions & 0 deletions includes/class-sst-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public static function get_tic( $product_id, $variation_id = 0 ) {
return empty( $final_tic ) ? null : $final_tic;
}

/**
* Is the given TIC a guns or ammo TIC?
*
* @param int $tic TIC.
*
* @return bool
* @since 8.4.4
*/
public static function is_gun_or_ammo_tic( $tic ) {
return in_array( (int) $tic, array( 90505, 90506 ) );
}

/**
* Output "Shipping Origin Addresses" select box.
*
Expand Down
24 changes: 22 additions & 2 deletions includes/frontend/class-sst-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,29 @@ protected function create_packages() {
$packages = array_merge( $packages, $this->split_package( $raw_package ) );
}

// Add fees to first package.
// Add fees to packages.
if ( ! empty( $packages ) && apply_filters( 'wootax_add_fees', true ) ) {
$packages[ key( $packages ) ]['fees'] = $this->cart->get_fees();
foreach ( $this->cart->get_fees() as $key => $fee ) {
$target_package_key = key( $packages );

if ( 'co-excise-tax' === $fee->id || 'CO EXCISE TAX' === strtoupper( $fee->name ) ) {
foreach ( $packages as $pkg_key => $pkg ) {
foreach ( $pkg['contents'] as $content ) {
$tic = SST_Product::get_tic( $content['product_id'], $content['variation_id'] );
if ( SST_Product::is_gun_or_ammo_tic( $tic ) ) {
$target_package_key = $pkg_key;
break 2;
}
}
}
}

if ( ! isset( $packages[ $target_package_key ] ) ) {
$target_package_key = key( $packages );
}

$packages[ $target_package_key ]['fees'][ $key ] = $fee;
}
}

// Debug Logging
Expand Down
Loading