Advertisement
wclovers

Untitled

Jun 5th, 2023
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. add_filter('woocommerce_available_payment_gateways', function ($available_gateways) {
  2.     global $WCFM;
  3.  
  4.     if (!is_admin() && isset($available_gateways['cod']) && WC()->cart) {
  5.         $cod_available = false;
  6.  
  7.         foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
  8.             $cod_available = false;
  9.             $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
  10.  
  11.             if ($_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters('woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key)) {
  12.                 $vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product($_product->get_id());
  13.  
  14.                 if (!$vendor_id || !wcfm_is_vendor($vendor_id)) {
  15.                     continue;
  16.                 }
  17.  
  18.                 $vendor_data = get_user_meta($vendor_id, 'wcfmmp_profile_settings', true);
  19.  
  20.                 if (!$vendor_data) {
  21.                     $vendor_data = array();
  22.                 }
  23.  
  24.                 $is_cod_enabled = isset($vendor_data['payment']['wcfm_cod_enabled']) ? 'yes' : 'no';
  25.  
  26.                 if ($is_cod_enabled == 'yes') {
  27.                     $cod_available = true;
  28.                 }
  29.             }
  30.         }
  31.  
  32.         // Unset COD if (!$cod_available || (WC()->customer && WC()->customer->get_billing_country() != 'AE'))
  33.         if (!$cod_available || (WC()->customer && WC()->customer->get_billing_country() != 'AE')) {
  34.             unset($available_gateways['cod']);
  35.         }
  36.     }
  37.  
  38.     return $available_gateways;
  39. }, 200);
  40.  
  41. // Vendor Setting
  42. add_filter('wcfm_marketplace_settings_fields_billing', function ($vendor_billing_fields, $vendor_id) {
  43.     $vendor_data = get_user_meta($vendor_id, 'wcfmmp_profile_settings', true);
  44.  
  45.     if (!$vendor_data) {
  46.         $vendor_data = array();
  47.     }
  48.  
  49.     $is_cod_enabled = isset($vendor_data['payment']['wcfm_cod_enabled']) ? 'yes' : 'no';
  50.  
  51.     $vendor_wcfm_cod_enabled_fields = array(
  52.         'wcfm_cod_enabled' => array(
  53.             'label' => __('COD Enable for Checkout', 'wc-frontend-manager'),
  54.             'name' => 'payment[wcfm_cod_enabled]',
  55.             'type' => 'checkbox',
  56.             'class' => 'wcfm-checkbox wcfm_ele',
  57.             'label_class' => 'wcfm_title wcfm_ele checkbox_title',
  58.             'value' => 'yes',
  59.             'dfvalue' => $is_cod_enabled
  60.         ),
  61.     );
  62.  
  63.     $vendor_billing_fields = array_merge($vendor_wcfm_cod_enabled_fields, $vendor_billing_fields);
  64.     return $vendor_billing_fields;
  65. }, 50, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement