在后端,客户需要在单击“添加订单”之前“免征增值税”。
你可以试着用钩子
save_post_shop_order
在订单数据保存到后端之前触发,方式如下:
add_action( 'save_post_shop_order', 'backend_remove_tax_from_user', 50, 3 );
function backend_remove_tax_from_user( $post_id, $post, $update ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id; // Exit if it's an autosave
if ( $post->post_status != 'publish' )
return $post_id; // Exit if not 'publish' post status
if ( ! current_user_can( 'edit_order', $post_id ) )
return $post_id; // Exit if user is not allowed
if( ! isset($_POST['customer_user']) ) return $post_id; // Exit
if( $_POST['customer_user'] > 0 ){
$customer_id = intval($_POST['customer_user']);
if( get_field('steuer_befreit', "user_{$customer_id}") ){
$wc_customer = new WC_Customer( $customer_id );
$wc_customer->set_is_vat_exempt( true );
}
}
}
代码进入功能。活动子主题(或主题)的php文件。
但这行不通
你将无法用任何现有的钩子来实现这一点。唯一的方法是让第一个客户免除增值税,然后您可以为该客户添加订单。