Advertisement
Fany_VanDaal

Omezení způsobu platby podle kategorie

May 23rd, 2019
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. // vypnutí platby pro zvolenou kategorii produktů - platba pouze převodem
  2. add_filter('woocommerce_available_payment_gateways','vandaal_unset_gateway_by_category');
  3. function vandaal_unset_gateway_by_category($available_gateways)
  4. {
  5.     global $woocommerce;
  6.     $super_final_cat = '';
  7.  
  8.     $category_IDs = array(121); // zde vložte ID kategorií, které chcete limitovat na způsob platby
  9.     foreach ($woocommerce->cart->cart_contents as $key => $values )
  10.     {
  11.         $terms = get_the_terms( $values['product_id'], 'product_cat' );    
  12.         foreach ($terms as $term)
  13.         {
  14.             $product_cat_id = $term->term_id;
  15.             $product_parent_categories_all_hierachy = get_ancestors( $product_cat_id, 'product_cat' );  
  16.             $last_parent_cat = array_slice($product_parent_categories_all_hierachy, -1, 1, true);
  17.             foreach($last_parent_cat as $last_parent_cat_value)
  18.             {
  19.                 $super_final_cat = $last_parent_cat_value;
  20.             }
  21.  
  22.             if((in_array($term->term_id, $category_IDs)) OR ($term->term_id = $super_final_cat))
  23.             {
  24.             // zde zadejte všechny způsoby platby, které se mají zakázat, pokud je v košíku zboží z určité kategorie
  25.             // názvy zjistíte ve woocommerce->nastavení->pokladna a dole výpis povolených způsobů plateb
  26.                 unset( $available_gateways['cheque'] );
  27.                 unset( $available_gateways['paypal'] );
  28.                 unset( $available_gateways['gopay'] );
  29.                 unset( $available_gateways['cod'] );
  30.                 break;
  31.             }
  32.             break;
  33.         }
  34.     }
  35.     return $available_gateways;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement