Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wc_diff_rate_for_user( string $tax_class, WC_Product $product ): string {
- // Ottenere l'utente corrente
- $current_user = wp_get_current_user();
- $current_user_data = get_userdata($current_user->ID);
- // Fix se manda in crash la visualizzazione dei prodotti a backend
- if( ! isset( WC()->customer ) ) return $tax_class;
- $country = WC()->customer->get_shipping_country();
- $meta_IT = get_user_meta($current_user->ID, 'afreg_additional_9612', true);
- $meta_EN = get_user_meta($current_user->ID, 'afreg_additional_9613', true);
- $meta_FR = get_user_meta($current_user->ID, 'afreg_additional_9790', true);
- $meta_ES = get_user_meta($current_user->ID, 'afreg_additional_10215', true);
- $lingua_corrente = apply_filters( 'wpml_current_language', NULL );
- // Se nella lingua inglese
- if($lingua_corrente == 'en'){
- if ($current_user->exists()) {
- // Se professionista che ha messo il check che ha il VIES
- if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
- if ($meta_EN == "Si" || $meta_EN == ""){
- // Esente IVA
- $tax_class = 'Zero Rate';
- }
- }
- }
- }
- // Se nella lingua italiana
- elseif($lingua_corrente == 'it') {
- // Se professionista che ha messo il check che ha il VIES
- if ($current_user->exists()) {
- if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
- if ($meta_IT == "Si" || $meta_IT == "" ){
- // Esente IVA
- $tax_class = 'Zero Rate';
- }
- }
- }
- }
- // Se nella lingua francese
- elseif($lingua_corrente == 'fr') {
- // Se professionista che ha messo il check che ha il VIES
- if ($current_user->exists()) {
- if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
- if ($meta_FR == "Si" || $meta_FR == "" ){
- // Esente IVA
- $tax_class = 'Zero Rate';
- }
- }
- }
- }
- // Se nella lingua spagnola
- elseif($lingua_corrente == 'es') {
- // Se professionista che ha messo il check che ha il VIES
- if ($current_user->exists()) {
- if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
- if ($meta_ES == "Si" || $meta_ES == "" ){
- // Esente IVA
- $tax_class = 'Zero Rate';
- }
- }
- }
- }
- // Altrimenti per tutto il resto, ovvero pro senza partita iva e clienti applico IVA
- else{
- $tax_class = 'Standard';
- }
- return $tax_class;
- }
- add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );
- add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment