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
11 changes: 9 additions & 2 deletions includes/abstracts/class-sst-abstract-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public function filter_excise_tax_tic( $tic, $fee ) {
* @since 5.0
*/
public function calculate_taxes() {

// Integration disabled?
if ( 'yes' === SST_Settings::get( 'disable_integration' )) {
SST_Logger::add( __( 'Integration disabled. Skipping tax calculation.', 'simple-sales-tax' ) );
return false;
}

$this->reset_taxes();

// No API Login ID or API Key? Bail.
Expand All @@ -80,7 +87,7 @@ public function calculate_taxes() {
foreach ( $this->do_lookup() as $package ) {

// Real-time tax calculation is disabled?.
if ( 'yes' === SST_Settings::get( 'disable_real_time_calc' )) {
if ( 'data_mover' === sst_integration_mode() ) {
SST_Logger::add( __( 'Real-time tax calculation is disabled. Calculating tax from saved packages.', 'simple-sales-tax' ), $package );
continue;
}
Expand Down Expand Up @@ -216,7 +223,7 @@ protected function do_lookup() {
*/
protected function do_package_lookup( $package ) {
// Skip lookup if real-time tax calculation is disabled. [Data Import Mode]
if ( 'yes' === SST_Settings::get( 'disable_real_time_calc' )) {
if ( 'data_mover' === sst_integration_mode() ) {
SST_Logger::add( __( 'Real-time tax calculation is disabled. Skipping lookup.', 'simple-sales-tax' ) );
return $package;
}
Expand Down
24 changes: 21 additions & 3 deletions includes/class-sst-order-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public function __construct() {
* @since 5.0
*/
public function capture_order( $_order_id, $order ) {
// Disable integration
if ( 'yes' === SST_Settings::get( 'disable_integration' ) ) {
SST_Logger::order_log( __( 'Integration disabled. Skipping order capture.', 'simple-sales-tax' ), $order->get_id() );
return false;
}

$sst_order = new SST_Order( $order );

// Logging
Expand Down Expand Up @@ -111,6 +117,12 @@ public function refund_order( $refund_id, $args ) {
* @since 5.0
*/
public function maybe_capture_order( $order_id ) {
// Disable integration
if ( 'yes' === SST_Settings::get( 'disable_integration' ) ) {
SST_Logger::order_log( __( 'Integration disabled. Skipping order capture.', 'simple-sales-tax' ), $order_id );
return;
}

if ( 'yes' === SST_Settings::get( 'capture_immediately' ) ) {
$order = new SST_Order( $order_id );

Expand Down Expand Up @@ -184,12 +196,18 @@ public function calculate_order_tax( $and_taxes, $order ) {
return;
}

// Disable integration
if ( 'yes' === SST_Settings::get( 'disable_integration' ) ) {
SST_Logger::order_log( __( 'Integration disabled. Skipping order tax calculation.', 'simple-sales-tax' ), $order->get_id() );
return;
}

/**
* Real-time tax calculation is disabled?
* Data mover mode
* @since 8.4.1
*/
if ( 'yes' === SST_Settings::get( 'disable_real_time_calc' )) {
SST_Logger::add( __( 'Real-time tax calculation is disabled. Skipping order tax calculation.', 'simple-sales-tax' ) );
if ( 'data_mover' === sst_integration_mode() ) {
SST_Logger::order_log( __( 'Data mover mode. Skipping order tax calculation.', 'simple-sales-tax' ), $order->get_id() );
return;
}

Expand Down
5 changes: 2 additions & 3 deletions includes/class-sst-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,8 @@ public function do_capture() {
}
}

// V3: Data Mover Mode.
$data_mover = SST_Settings::get( 'data_mover' );
if ( $data_mover ) {
// Data Mover Mode.
if ( 'data_mover' === sst_integration_mode() ) {
// Logging
SST_Logger::order_log( __( 'Data Mover Mode enabled. Creating order in TaxCloud.', 'simple-sales-tax' ), $order->get_id() );
$created_order = $this->create_order_in_taxcloud( $packages, $order );
Expand Down
6 changes: 3 additions & 3 deletions includes/class-sst-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,16 @@ public static function get_form_fields() {
),
'desc_tip' => true,
),
'disable_real_time_calc' => array(
'title' => __( 'Disable Real-Time Tax Calculation', 'simple-sales-tax' ),
'disable_integration' => array(
'title' => __( 'Disable Integration', 'simple-sales-tax' ),
'type' => 'select',
'options' => array(
'no' => __( 'No', 'simple-sales-tax' ),
'yes' => __( 'Yes', 'simple-sales-tax' ),
),
'default' => 'no',
'description' => __(
'If enabled, real-time sales tax calculations will be disabled during cart and checkout',
'If enabled, TaxCloud integration will be disabled for both real-time and data mover.',
'simple-sales-tax'
),
'desc_tip' => true,
Expand Down
43 changes: 8 additions & 35 deletions includes/class-sst-taxcloud-v3.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,54 +44,27 @@ public static function instance() {
*/
protected function __construct() {
add_action( 'sst_update_data_mover_settings', array( 'SST_TaxCloud_V3_API', 'update_data_mover_settings' ) );
add_filter( 'sst_get_option', array( $this, 'update_realtime_calc_option' ), 10, 2 );
add_filter( 'sst_settings_form_fields', array( $this, 'disable_real_time_calc_option' ), 10, 2 );
add_filter( 'sst_get_option', array( $this, 'update_show_tax_option' ), 10, 2 );
}

/**
* Disable the disable_real_time_calc option if data mover is true.
*
* @param array $fields Array of settings fields.
* @param array $settings Current settings.
*
* @return array Updated settings fields.
* @since 8.4.1
*/
public function disable_real_time_calc_option( $fields, $settings ) {
$data_mover = isset( $settings['data_mover'] ) ? (bool) $settings['data_mover'] : false;
if( $data_mover ) {
$fields['disable_real_time_calc']['disabled'] = $data_mover;
$fields['disable_real_time_calc']['options'] = array(
'yes' => __( 'Yes', 'simple-sales-tax' ),
);
}
return $fields;
}


/**
* Update the disable_real_time_calc option if data mover is true.
* Update the show_zero_tax option if disable_integration is true.
*
* @param string $value Value of the option.
* @param string $key Key of the option.
*
* @return string Updated value.
* @since 8.4.1
*/
public function update_realtime_calc_option( $value, $key ) {
if( 'disable_real_time_calc' === $key ) {
$data_mover = SST_Settings::get( 'data_mover', false );
if( $data_mover ) {
return 'yes';
}
} elseif ( 'show_zero_tax' === $key ) {
$disable_real_time_calc = SST_Settings::get( 'disable_real_time_calc', 'no' );
if( 'yes' === $disable_real_time_calc ) {
public function update_show_tax_option( $value, $key ) {
if ( 'show_zero_tax' === $key ) {
$disable_integration = SST_Settings::get( 'disable_integration', 'no' );
if( 'yes' === $disable_integration ) {
return 'no';
}
} elseif ( 'order_show_zero_tax' === $key ) {
$disable_real_time_calc = SST_Settings::get( 'disable_real_time_calc', 'no' );
if( 'yes' === $disable_real_time_calc ) {
$disable_integration = SST_Settings::get( 'disable_integration', 'no' );
if( 'yes' === $disable_integration ) {
return 'no';
}
}
Expand Down
11 changes: 7 additions & 4 deletions includes/frontend/class-sst-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public function __construct() {
* @since 5.0
*/
public function calculate_tax_totals( $total, $cart ) {
// Disable tax calculation if integration is disabled
if ( 'yes' === SST_Settings::get( 'disable_integration', 'no' ) ) {
return $total;
}

// The Tax Exemption for WooCommerce (PRO) plugin sets the
// is_tax_exempt session variable, and we need to respect that so we
// can allow customers that aren't logged in to show no tax when
Expand All @@ -102,8 +107,6 @@ public function calculate_tax_totals( $total, $cart ) {
return $total;
}



$tax_total = 0;

$this->cart = new SST_Cart_Proxy( $cart );
Expand All @@ -124,8 +127,8 @@ public function calculate_tax_totals( $total, $cart ) {
* Skip tax calculation if real-time tax calculation is disabled. [Data Import Mode]
* @since 8.4.1
*/
if ( 'yes' === SST_Settings::get( 'disable_real_time_calc' )) {
SST_Logger::add( __( 'Real-time tax calculation is disabled. Skipping tax calculation.', 'simple-sales-tax' ) );
if ( 'data_mover' === sst_integration_mode() ) {
SST_Logger::add( __( 'Data mover mode. Skipping tax calculation.', 'simple-sales-tax' ) );
return $total;
}

Expand Down
11 changes: 11 additions & 0 deletions includes/sst-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,15 @@ function sst_get_rate_label() {
*/
function sst_get_rate_code() {
return apply_filters( 'wootax_rate_code', 'SALES-TAX' );
}

/**
* Get the integration mode.
*
* @since 8.4.5
* @return string Integration mode
*/
function sst_integration_mode() {
$data_mover = SST_Settings::get( 'data_mover', false );
return $data_mover == false ? 'realtime' : 'data_mover';
}
Loading