/**
  * Maybe capture order immediately after checkout
  *
  * @since 4.5
  */
 public static function maybe_capture_order($order_id)
 {
     if (WC_WooTax::get_option('capture_immediately') == 'yes') {
         $res = self::capture_order($order_id, true);
         if ($res !== true && self::$logger) {
             self::$logger->add('wootax', 'Failed to capture order ' . $order_id . ' after checkout.');
         }
     }
 }
function wt_do_template_substitutions($content)
{
    return str_replace(array('{PLUGIN_PATH}', '{COMPANY_NAME}'), array(WT_PLUGIN_DIR_URL, WC_WooTax::get_option('company_name')), $content);
}
/**
 * Returns the email to which WooTax notifications should be sent
 * If the notification_email is not set explicitly, return first admin email
 *
 * @since 4.4
 * @return (string) email address
 */
function wootax_get_notification_email()
{
    $email = WC_WooTax::get_option('notification_email');
    if ($email) {
        return $email;
    }
    $all_admins = get_users(array('role' => 'administrator', 'number' => 1));
    return $all_admins[0]->user_email;
}
/** 
 * Return instance of WC_WooTax_TaxCloud class, optionally initialized with Login ID/Key
 * If no login ID/key are provided, use stored settings
 *
 * @since 4.4
 * @param (string) $login_id optional API Login ID
 * @param (string) $login_key optional API Login Key
 */
function TaxCloud($login_id = false, $login_key = false)
{
    if (!$login_id) {
        $login_id = WC_WooTax::get_option('tc_id');
    }
    if (!$login_key) {
        $login_key = WC_WooTax::get_option('tc_key');
    }
    $instance = WC_WooTax_TaxCloud::instance();
    $instance->set_id($login_id);
    $instance->set_key($login_key);
    return $instance;
}
        /**
         * Output address table
         */
        public function generate_address_table_html($key, $data)
        {
            $woocommerce_path = plugin_dir_url('woocommerce/woocommerce.php');
            ob_start();
            ?>
 		</table>
 		<table id="address_table" class="shippingrows widefat">
			<thead>
				<tr>
					<th><span>Address 1</span> <img class="help_tip" data-tip="Line 1 of your business address." src="<?php 
            echo $woocommerce_path;
            ?>
/assets/images/help.png" height="16" width="16"></th>
					<th><span>Address 2</span> <img class="help_tip" data-tip="Line 2 of your business address." src="<?php 
            echo $woocommerce_path;
            ?>
/assets/images/help.png" height="16" width="16"></th>
					<th><span>City</span> <img class="help_tip" data-tip="The city in which your business operates." src="<?php 
            echo $woocommerce_path;
            ?>
/assets/images/help.png" height="16" width="16"></th>
					<th><span>State</span> <img class="help_tip" data-tip="The state where your business is located." src="<?php 
            echo $woocommerce_path;
            ?>
/assets/images/help.png" height="16" width="16"></th>
					<th><span>ZIP Code</span> <img class="help_tip" data-tip="5 or 9-digit ZIP code of your business address." src="<?php 
            echo $woocommerce_path;
            ?>
/assets/images/help.png" height="16" width="16"></th>
					<th><span>Make Default</span> <img class="help_tip" data-tip="Check this if you want an address to be used as the default 'Shipment Origin Address' for your products. If you only have one business address, it will be used as your default address automatically." src="<?php 
            echo $woocommerce_path;
            ?>
/assets/images/help.png" height="16" width="16"></th>
					<th><span>Remove</span> <img class="help_tip" data-tip="Click the red X to remove a business address. Remember, at least one valid address is required for WooTax to work." src="<?php 
            echo $woocommerce_path;
            ?>
/assets/images/help.png" height="16" width="16"></th> 
				</tr>
			</thead>
			<tfoot>
				<tr>
					<th colspan="7">
						<button class="wp-core-ui button-secondary add-address-row">Add Address</button>
					</th>
				</tr>
			</tfoot>
			<tbody>
			<?php 
            $addresses = fetch_business_addresses();
            for ($i = 0; $i < count($addresses); $i++) {
                $address = $addresses[$i];
                ?>
					<tr>
						<td>
							<input type="text" name="wootax_address1[<?php 
                echo $i;
                ?>
]" class="wootax_address1" value="<?php 
                echo $address['address_1'];
                ?>
" />
						</td>
						<td>
							<input type="text" name="wootax_address2[<?php 
                echo $i;
                ?>
]" class="wootax_address2" value="<?php 
                echo isset($address['address_2']) ? $address['address_2'] : '';
                ?>
" placeholder="(Optional)" />
						</td>
						<td>
							<input type="text" name="wootax_city[<?php 
                echo $i;
                ?>
]" class="wootax_city" value="<?php 
                echo $address['city'];
                ?>
" />
						</td>
						<td>
							<select name="wootax_state[<?php 
                echo $i;
                ?>
]" class="wootax_state">
								<option value="">Select One</option>
								<option value="AL"<?php 
                echo $address['state'] == 'AL' ? ' selected' : '';
                ?>
>Alabama</option> 
								<option value="AK"<?php 
                echo $address['state'] == 'AK' ? ' selected' : '';
                ?>
>Alaska</option> 
								<option value="AZ"<?php 
                echo $address['state'] == 'AZ' ? ' selected' : '';
                ?>
>Arizona</option> 
								<option value="AR"<?php 
                echo $address['state'] == 'AR' ? ' selected' : '';
                ?>
>Arkansas</option> 
								<option value="CA"<?php 
                echo $address['state'] == 'CA' ? ' selected' : '';
                ?>
>California</option> 
								<option value="CO"<?php 
                echo $address['state'] == 'CO' ? ' selected' : '';
                ?>
>Colorado</option> 
								<option value="CT"<?php 
                echo $address['state'] == 'CT' ? ' selected' : '';
                ?>
>Connecticut</option> 
								<option value="DE"<?php 
                echo $address['state'] == 'DE' ? ' selected' : '';
                ?>
>Delaware</option> 
								<option value="DC"<?php 
                echo $address['state'] == 'DC' ? ' selected' : '';
                ?>
>District Of Columbia</option> 
								<option value="FL"<?php 
                echo $address['state'] == 'FL' ? ' selected' : '';
                ?>
>Florida</option> 
								<option value="GA"<?php 
                echo $address['state'] == 'GA' ? ' selected' : '';
                ?>
>Georgia</option> 
								<option value="HI"<?php 
                echo $address['state'] == 'HI' ? ' selected' : '';
                ?>
>Hawaii</option> 
								<option value="ID"<?php 
                echo $address['state'] == 'ID' ? ' selected' : '';
                ?>
>Idaho</option> 
								<option value="IL"<?php 
                echo $address['state'] == 'IL' ? ' selected' : '';
                ?>
>Illinois</option> 
								<option value="IN"<?php 
                echo $address['state'] == 'IN' ? ' selected' : '';
                ?>
>Indiana</option> 
								<option value="IA"<?php 
                echo $address['state'] == 'IA' ? ' selected' : '';
                ?>
>Iowa</option> 
								<option value="KS"<?php 
                echo $address['state'] == 'KS' ? ' selected' : '';
                ?>
>Kansas</option> 
								<option value="KY"<?php 
                echo $address['state'] == 'KY' ? ' selected' : '';
                ?>
>Kentucky</option> 
								<option value="LA"<?php 
                echo $address['state'] == 'LA' ? ' selected' : '';
                ?>
>Louisiana</option> 
								<option value="ME"<?php 
                echo $address['state'] == 'ME' ? ' selected' : '';
                ?>
>Maine</option> 
								<option value="MD"<?php 
                echo $address['state'] == 'MD' ? ' selected' : '';
                ?>
>Maryland</option> 
								<option value="MA"<?php 
                echo $address['state'] == 'MA' ? ' selected' : '';
                ?>
>Massachusetts</option> 
								<option value="MI"<?php 
                echo $address['state'] == 'MI' ? ' selected' : '';
                ?>
>Michigan</option> 
								<option value="MN"<?php 
                echo $address['state'] == 'MN' ? ' selected' : '';
                ?>
>Minnesota</option> 
								<option value="MS"<?php 
                echo $address['state'] == 'MS' ? ' selected' : '';
                ?>
>Mississippi</option> 
								<option value="MO"<?php 
                echo $address['state'] == 'MO' ? ' selected' : '';
                ?>
>Missouri</option> 
								<option value="MT"<?php 
                echo $address['state'] == 'MT' ? ' selected' : '';
                ?>
>Montana</option> 
								<option value="NE"<?php 
                echo $address['state'] == 'NE' ? ' selected' : '';
                ?>
>Nebraska</option> 
								<option value="NV"<?php 
                echo $address['state'] == 'NV' ? ' selected' : '';
                ?>
>Nevada</option> 
								<option value="NH"<?php 
                echo $address['state'] == 'NH' ? ' selected' : '';
                ?>
>New Hampshire</option> 
								<option value="NJ"<?php 
                echo $address['state'] == 'NJ' ? ' selected' : '';
                ?>
>New Jersey</option> 
								<option value="NM"<?php 
                echo $address['state'] == 'NM' ? ' selected' : '';
                ?>
>New Mexico</option> 
								<option value="NY"<?php 
                echo $address['state'] == 'NY' ? ' selected' : '';
                ?>
>New York</option> 
								<option value="NC"<?php 
                echo $address['state'] == 'NC' ? ' selected' : '';
                ?>
>North Carolina</option> 
								<option value="ND"<?php 
                echo $address['state'] == 'ND' ? ' selected' : '';
                ?>
>North Dakota</option> 
								<option value="OH"<?php 
                echo $address['state'] == 'OH' ? ' selected' : '';
                ?>
>Ohio</option> 
								<option value="OK"<?php 
                echo $address['state'] == 'OK' ? ' selected' : '';
                ?>
>Oklahoma</option> 
								<option value="OR"<?php 
                echo $address['state'] == 'OR' ? ' selected' : '';
                ?>
>Oregon</option> 
								<option value="PA"<?php 
                echo $address['state'] == 'PA' ? ' selected' : '';
                ?>
>Pennsylvania</option> 
								<option value="RI"<?php 
                echo $address['state'] == 'RI' ? ' selected' : '';
                ?>
>Rhode Island</option> 
								<option value="SC"<?php 
                echo $address['state'] == 'SC' ? ' selected' : '';
                ?>
>South Carolina</option> 
								<option value="SD"<?php 
                echo $address['state'] == 'SD' ? ' selected' : '';
                ?>
>South Dakota</option> 
								<option value="TN"<?php 
                echo $address['state'] == 'TN' ? ' selected' : '';
                ?>
>Tennessee</option> 
								<option value="TX"<?php 
                echo $address['state'] == 'TX' ? ' selected' : '';
                ?>
>Texas</option> 
								<option value="UT"<?php 
                echo $address['state'] == 'UT' ? ' selected' : '';
                ?>
>Utah</option> 
								<option value="VT"<?php 
                echo $address['state'] == 'VT' ? ' selected' : '';
                ?>
>Vermont</option> 
								<option value="VA"<?php 
                echo $address['state'] == 'VA' ? ' selected' : '';
                ?>
>Virginia</option> 
								<option value="WA"<?php 
                echo $address['state'] == 'WA' ? ' selected' : '';
                ?>
>Washington</option> 
								<option value="WV"<?php 
                echo $address['state'] == 'WV' ? ' selected' : '';
                ?>
>West Virginia</option> 
								<option value="WI"<?php 
                echo $address['state'] == 'WI' ? ' selected' : '';
                ?>
>Wisconsin</option> 
								<option value="WY"<?php 
                echo $address['state'] == 'WY' ? ' selected' : '';
                ?>
>Wyoming</option>
							</select>
						</td>
						<td>
							<input type="text" name="wootax_zip5[<?php 
                echo $i;
                ?>
]" class="wootax_zip5" value="<?php 
                echo $address['zip5'];
                ?>
" /> - <input type="text" name="wootax_zip4[<?php 
                echo $i;
                ?>
]" value="<?php 
                echo $address['zip4'];
                ?>
" placeholder="(Optional)" class="wootax_zip4" />
						</td>
						<td>
							<input type="radio" name="wootax_default_address" value="<?php 
                echo $i;
                ?>
"<?php 
                echo WC_WooTax::get_option('default_address') == $i || WC_WooTax::get_option('default_address') == '' && $i == 0 ? ' checked' : '';
                ?>
 />
						</td>
						<td>
							<a class="remove_address<?php 
                echo $i == 0 ? ' disabled' : '';
                ?>
">x</a>
						</td>
					</tr>
					<?php 
            }
            ?>
			</tbody>
		</table>
		<table class="form-table">
 		<?php 
            return ob_get_clean();
        }
 /**
  * Include WooTax dependencies
  *
  * @since 4.4
  */
 private static function includes()
 {
     // Used for all request types
     require 'includes/wc-wootax-functions.php';
     require 'classes/class-wc-wootax-taxcloud.php';
     // Used on frontend
     if (self::is_request('frontend')) {
         if (WC_WooTax::get_option('show_exempt') == 'true') {
             require 'includes/wc-wootax-exemptions.php';
         }
         require 'classes/class-wc-wootax-checkout.php';
     }
     // Frontend and admin panel
     if (self::is_request('frontend') || self::is_request('admin') || self::is_request('cron')) {
         require 'classes/class-wc-wootax-order.php';
         require 'classes/class-wt-orders.php';
         if (WT_SUBS_ACTIVE) {
             require 'classes/class-wc-wootax-subscriptions.php';
         }
         require 'includes/wc-wootax-cron-tasks.php';
     }
     // Strictly admin panel
     if (self::is_request('admin')) {
         require 'classes/class-wc-wootax-upgrade.php';
         require 'classes/class-wc-wootax-settings.php';
         require 'classes/class-wc-wootax-admin.php';
         require 'classes/class-wc-wootax-refund.php';
         require 'classes/WT_Plugin_Updater.php';
     }
 }
 /**
  * Update order shipping/cart tax total
  *
  * @since 4.4
  * @param (string) $type "shipping" to update shipping tax total; "cart" to update cart tax total
  * @param (float) $new_tax new value for tax
  */
 private function update_tax_total($type, $new_tax)
 {
     if ($type == 'shipping') {
         $tax_key = 'shipping_taxes';
         $total_key = 'shipping_tax_total';
     } else {
         $tax_key = 'taxes';
         $total_key = 'tax_total';
     }
     $this->cart->{$tax_key}[WT_RATE_ID] = $new_tax;
     if (!WT_SUBS_ACTIVE || !WC_Subscriptions_Cart::cart_contains_subscription()) {
         // Removing zero tax row causes display issues for subscription orders
         if (WC_WooTax::get_option('show_zero_tax') != 'true' && $new_tax == 0) {
             unset($this->cart->{$tax_key}[WT_RATE_ID]);
         }
     }
     // Use get_tax_total to set new tax total so we don't override other rates
     $this->cart->{$total_key} = version_compare(WOOCOMMERCE_VERSION, '2.2', '>=') ? WC_Tax::get_tax_total($this->cart->{$tax_key}) : $this->cart->tax->get_tax_total($this->cart->{$tax_key});
     $this->{$total_key} = $new_tax;
 }