1 回答

TA貢獻2037條經驗 獲得超6個贊
由于 Woocommerce 3woocommerce_product_tax_class鉤子已被棄用并已被替換。我已經更新了您的第三個功能:
// Add tax exempt custom user field in admin
add_action( 'show_user_profile', 'add_customer_tax_exempt_checkbox', 10 );
add_action( 'edit_user_profile', 'add_customer_tax_exempt_checkbox', 10 );
function add_customer_tax_exempt_checkbox( $user )
{
?>
<h3><?php _e("Tax status"); ?></h3>
<table class="form-table">
<tr>
<th><?php _e("Tax exempt"); ?></th>
<td>
<?php
woocommerce_form_field( 'tax_exempt', array(
'type' => 'checkbox',
'class' => array('input-checkbox'),
'label' => __('Allowed'),
), get_user_meta( $user->id, 'tax_exempt', true ) );
?>
</td>
</tr>
</table>
<?php
}
// Save allowed custom user field in admin
add_action( 'personal_options_update', 'save_customer_tax_exempt_checkbox' );
add_action( 'edit_user_profile_update', 'save_customer_tax_exempt_checkbox' );
function save_customer_tax_exempt_checkbox( $user_id )
{
if ( current_user_can( 'edit_user', $user_id ) ) {
update_user_meta( $user_id, 'tax_exempt', isset($_POST['tax_exempt']) ? '1' : '0' );
}
}
// Enabling or disabling tax calculation at checkout
add_filter( 'woocommerce_product_get_tax_class', 'disable_tax_calculation', 10, 2 );
add_filter( 'woocommerce_product_variation_get_tax_class', 'disable_tax_calculation', 10, 2 );
function disable_tax_calculation( $tax_class, $product ) {
if ( get_user_meta( get_current_user_id(), 'tax_exempt', true ) ) {
$tax_class = 'Zero Rate';
}
return $tax_class;
}
代碼位于活動子主題(或活動主題)的functions.php 文件中。它應該更好地工作。
- 1 回答
- 0 關注
- 181 瀏覽
添加回答
舉報