emiliano1991

New Version

Sep 9th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.87 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.     $lingua_corrente = apply_filters( 'wpml_current_language', NULL );
  17.  
  18.     // Se nella lingua inglese
  19.     if($lingua_corrente == 'en'){
  20.         if ($current_user->exists()) {
  21.         // Se professionista che ha messo il check che ha il VIES
  22.         if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
  23.             if ($meta_EN == "Si" || $meta_EN == ""){
  24.                 // Esente IVA
  25.                 $tax_class = 'Zero Rate';
  26.             }
  27.         }
  28.     }
  29.     }
  30.     // Se nella lingua italiana
  31.     elseif($lingua_corrente == 'it') {
  32.         // Se professionista che ha messo il check che ha il VIES
  33.         if ($current_user->exists()) {
  34.         if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
  35.             if ($meta_IT == "Si" || $meta_IT == "" ){
  36.                 // Esente IVA
  37.                 $tax_class = 'Zero Rate';
  38.             }
  39.         }
  40.     }
  41.     }
  42.     // Se nella lingua francese
  43.     elseif($lingua_corrente == 'fr') {
  44.         // Se professionista che ha messo il check che ha il VIES
  45.         if ($current_user->exists()) {
  46.         if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
  47.             if ($meta_FR == "Si" || $meta_FR == "" ){
  48.                 // Esente IVA
  49.                 $tax_class = 'Zero Rate';
  50.             }
  51.         }
  52.     }
  53.     }
  54.     // Se nella lingua spagnola
  55.     elseif($lingua_corrente == 'es') {
  56.         // Se professionista che ha messo il check che ha il VIES
  57.         if ($current_user->exists()) {
  58.         if ( in_array( 'professionista', (array) $current_user_data->roles ) && $country !== 'IT'){
  59.             if ($meta_ES == "Si" || $meta_ES == "" ){
  60.                 // Esente IVA
  61.                 $tax_class = 'Zero Rate';
  62.             }
  63.         }
  64.     }
  65.      }
  66.     // Altrimenti per tutto il resto, ovvero pro senza partita iva e clienti applico IVA
  67.     else{
  68.         $tax_class = 'Standard';
  69.     }
  70.  
  71.     return $tax_class;
  72. }
  73.  
  74. add_filter( 'woocommerce_product_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );
  75. add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_diff_rate_for_user', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment