Completed

Change woocommerce tax rate with a checkbox in checkout page

Published on the November 22, 2017 in IT & Programming

About this project

Open

I need a checkbox in the checkout front end that change the tax rate of the order.

This code is a example that i need and it work fine, use a hack to trigger the ajax function that update the totals (explained here https://www.affectivia.com/blog/have-a-checkbox-on-the-checkout-page-which-updates-the-order-totals/)

//=============================================================================
// add tax exempt checkmark
// =============================================================================
add_action( 'woocommerce_after_order_notes', 'qd_tax_exempt');

function qd_tax_exempt( $checkout ) {

echo '<div id="qd-tax-exempt"><h3>'.__('Tax Exempt').'</H3>';

woocommerce_form_field( 'shipping_method_tax_exempt', array(
'type' => 'checkbox',
'class' => '',
'label' => __('My organization is tax exempt.'),
'Required' => false,
), $checkout->get_value( 'shipping_method_tax_exempt' ));

echo '</div>';
}

add_action( 'woocommerce_checkout_update_order_review', 'taxexempt_checkout_update_order_review');
function taxexempt_checkout_update_order_review( $post_data ) {
global $woocommerce;

$woocommerce->customer->set_is_vat_exempt(FALSE);

parse_str($post_data);

if ( isset($shipping_method_tax_exempt) && $shipping_method_tax_exempt == '1')
//here i need change the tax_rate not set the exempt
$woocommerce->customer->set_is_vat_exempt(true);
}

//***********************************************************************************

But i need that the checkbox above change the tax_rate of the order how this code do:


//Apply a different tax rate based on the user role.

Function wc_diff_rate_for_user( $tax_class, $product ) {
if ( is_user_logged_in() && current_user_can( 'administrator' ) ) {
$tax_class = 'name of the tax rate';
}
return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );


sumary: i need a checkbox in checkout page to change the tax rate by the user.

Category IT & Programming
Subcategory E-commerce
What is the scope of the project? Small change or bug
Is this a project or a position? Project
I currently have I have specifications
Required availability As needed
Experience in this type of projects Yes (I have managed this kind of project before)
API Integrations Other (Other APIs)
Roles needed Developer

Delivery term: November 24, 2017

Skills needed