Terminado

Change woocommerce tax rate with a checkbox in checkout page

Publicado el 22 Noviembre, 2017 en Programación y Tecnología

Sobre este proyecto

Abierto

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.

Categoría Programación y Tecnología
Subcategoría Tiendas Online (e-commerce)
¿Cuál es el alcance del proyecto? Bug o cambio pequeño
¿Es un proyecto o una posición? Un proyecto
Actualmente tengo Tengo las especificaciones
Disponibilidad requerida Según se necesite
Experiencia en este tipo de proyectos Sí (He administrado este tipo de proyectos anteriormente)
Integraciones de API Otros (Otras APIs)
Roles necesarios Programador

Plazo de Entrega: 24 Noviembre, 2017

Habilidades necesarias