在 WooCommerce 中,我使用插件 [WooCommerce 结帐插件][1],并且我在结帐页面添加了一个由单选按钮组成的附加字段(多项选择)。当客户在该单选按钮字段中选择特定选项时,我想更改税率。
基于根据所选付款方式答案代码更改 Woocommerce 购物车项目税级(更改特定付款方式的税率),我尝试自定义代码:
// Change Tax
add_action( 'woocommerce_before_calculate_totals', 'change_tax_class_based_on_radio_choice', 10, 1 );
function change_tax_class_based_on_radio_choice( $cart ) {
$installation = WC()->session->get('wc_checkout_add_ons') ; // This code must be change
$value = 'pas-dinstallation' ; // the value of the radio button "woocommerce checkout addon"
$value2 = 'bacs' ; // value of payement methode
$payement_methode = WC()->session->get('chosen_payment_method') ;
//if ( $payement_methode !== $value2 ) //this one is ok for change tax if payement methode is bank transfert …Run Code Online (Sandbox Code Playgroud)