emiliano1991

Old version

Sep 9th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. function wc_diff_rate_for_user( string $tax_class, WC_Product $product ): string {
  2.     // Ottenere l'utente corrente
  3.     $current_user = wp_get_current_user();
  4.     $current_user_data = get_userdata($current_user->ID);
  5.  
  6.     // Fix se manda in crash la visualizzazione dei prodotti a backend
  7.     if( ! isset( WC()->customer ) ) return $tax_class;
  8.  
  9.     $country = WC()->customer->get_shipping_country();
  10.  
  11.     $meta_IT = get_user_meta($current_user->ID, 'afreg_additional_9612', true);
  12.     $meta_EN = get_user_meta($current_user->ID, 'afreg_additional_9613', true);
  13.     $meta_FR = get_user_meta($current_user->ID, 'afreg_additional_9790', true);
  14.     $meta_ES = get_user_meta($current_user->ID, 'afreg_additional_10215', true);
  15.  
  16.     // Se nella lingua inglese
  17.     if (defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE == 'en') {
  18.         if ($current_user->exists()) {
  19.         // Se professionista che ha messo il check che ha il VIES
  20.         if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
  21.             if ($meta_EN == "Si" || $meta_EN == ""){
  22.                 // Esente IVA
  23.                 $tax_class = 'Zero Rate';
  24.             }
  25.         }
  26.     }
  27.     }
  28.     // Se nella lingua italiana
  29.     elseif(defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE == 'it') {
  30.         // Se professionista che ha messo il check che ha il VIES
  31.         if ($current_user->exists()) {
  32.         if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
  33.             if ($meta_IT == "Si" || $meta_IT == "" ){
  34.                 // Esente IVA
  35.                 $tax_class = 'Zero Rate';
  36.             }
  37.         }
  38.     }
  39.     }
  40.     // Se nella lingua francese
  41.     elseif(defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE == 'fr') {
  42.         // Se professionista che ha messo il check che ha il VIES
  43.         if ($current_user->exists()) {
  44.         if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
  45.             if ($meta_FR == "Si" || $meta_FR == "" ){
  46.                 // Esente IVA
  47.                 $tax_class = 'Zero Rate';
  48.             }
  49.         }
  50.     }
  51.     }
  52.     // Se nella lingua spagnola
  53.      elseif(defined('ICL_LANGUAGE_CODE') && ICL_LANGUAGE_CODE == 'es') {
  54.         // Se professionista che ha messo il check che ha il VIES
  55.         if ($current_user->exists()) {
  56.         if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
  57.             if ($meta_ES == "Si" || $meta_ES == "" ){
  58.                 // Esente IVA
  59.                 $tax_class = 'Zero Rate';
  60.             }
  61.         }
  62.     }
  63.      }
  64.     // Altrimenti per tutto il resto, ovvero pro senza partita iva e clienti applico IVA
  65.     else{
  66.         $tax_class = 'Standard';
  67.     }
  68.  
  69.     return $tax_class;
  70. }
  71.  
  72. add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );
  73. add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment