Skip to content

Commit

Permalink
add logic for colorado retail fee
Browse files Browse the repository at this point in the history
  • Loading branch information
iyut committed Dec 26, 2024
1 parent 5e38237 commit ccb29c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
17 changes: 14 additions & 3 deletions classes/class-wc-connect-custom-surcharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,22 @@ class WC_Connect_Custom_Surcharge {
* @return boolean.
*/
public static function get_us_co_eligibility( $cart = null ) {
if ( $cart instanceof WC_Cart ) {
return true;
if ( false === ( $cart instanceof WC_Cart ) ) {
return false;
}

return false;
$has_taxable_product = false;

foreach ( $cart->get_cart() as $cart_item ) {
if ( $cart_item['data']->is_taxable() ) {
$has_taxable_product = true;
break;
}
}

$content_taxes = $cart->get_cart_contents_taxes();

return $has_taxable_product && ! empty( $content_taxes );
}
}
}
11 changes: 6 additions & 5 deletions classes/class-wc-connect-taxjar-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1544,12 +1544,12 @@ public function add_custom_state_surcharge_fee( $cart ) {
$customer = WC()->customer;

foreach ( $this->get_custom_surcharges() as $key => $custom_info ) {
if ( $customer->get_shipping_country() . ':' . $customer->get_shipping_state() !== $key ) {
if ( $customer->get_shipping_country() . '-' . $customer->get_shipping_state() !== $key ) {
continue;
}

// Making sure all info is not empty.
if ( ! isset( $custom_info['function'] ) || ! isset( $custom_info['fee'] ) || ! isset( $custom_info['fee_text'] ) || ! is_float( $custom_info['fee'] ) || ! is_callable( $custom_info['function'], true ) ) {
if ( ! isset( $custom_info['function'] ) || ! isset( $custom_info['fee'] ) || ! isset( $custom_info['fee_text'] ) || ! is_float( $custom_info['fee'] ) || ! is_callable( $custom_info['function'] ) ) {
continue;
}

Expand All @@ -1562,11 +1562,12 @@ public function add_custom_state_surcharge_fee( $cart ) {
* @since 2.8.6
*
* @param boolean Custom surcharge toggle.
* @param string Custom surcharge area string. Example: "US-CO".
* @param array Custom surcharge info.
* @param WC_Cart WooCommerce cart object.
*/
if ( true === apply_filters( 'wc_services_apply_custom_surcharge_fee', $eligible_to_add_fee, $custom_info, $cart ) ) {
$cart->add_fee( $custom_info['fee_text'], $custom_info['fee'], true, 'standard' );
if ( true === apply_filters( 'wc_services_apply_custom_surcharge_fee', $eligible_to_add_fee, $key, $custom_info, $cart ) ) {
$cart->add_fee( $custom_info['fee_text'], $custom_info['fee'], true, 'standard' );
}
}
}
Expand All @@ -1588,7 +1589,7 @@ public function get_custom_surcharges() {
'wc_services_custom_surcharges',
array(
'US-CO' => array(
'function' => array( 'WC_Connect_Custom_Surcharge', 'get_us_co_custom_surcharge' ),
'function' => array( 'WC_Connect_Custom_Surcharge', 'get_us_co_eligibility' ),
'fee' => 0.27,
'fee_text' => __( 'Retail Delivery Fee', 'woocommerce_services' ),
)
Expand Down
1 change: 1 addition & 0 deletions woocommerce-services.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ public function load_dependencies() {
require_once __DIR__ . '/classes/class-wc-connect-logger.php';
require_once __DIR__ . '/classes/class-wc-connect-service-schemas-validator.php';
require_once __DIR__ . '/classes/class-wc-connect-taxjar-integration.php';
require_once __DIR__ . '/classes/class-wc-connect-custom-surcharge.php';
require_once __DIR__ . '/classes/class-wc-connect-error-notice.php';
require_once __DIR__ . '/classes/class-wc-connect-compatibility.php';
require_once __DIR__ . '/classes/class-wc-connect-compatibility-wcshipping-packages.php';
Expand Down

0 comments on commit ccb29c6

Please sign in to comment.