Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('woocommerce_available_payment_gateways', function ($available_gateways) {
- global $WCFM;
- if (!is_admin() && isset($available_gateways['cod']) && WC()->cart) {
- $cod_available = false;
- foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
- $cod_available = false;
- $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
- if ($_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters('woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key)) {
- $vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product($_product->get_id());
- if (!$vendor_id || !wcfm_is_vendor($vendor_id)) {
- continue;
- }
- $vendor_data = get_user_meta($vendor_id, 'wcfmmp_profile_settings', true);
- if (!$vendor_data) {
- $vendor_data = array();
- }
- $is_cod_enabled = isset($vendor_data['payment']['wcfm_cod_enabled']) ? 'yes' : 'no';
- if ($is_cod_enabled == 'yes') {
- $cod_available = true;
- }
- }
- }
- // Unset COD if (!$cod_available || (WC()->customer && WC()->customer->get_billing_country() != 'AE'))
- if (!$cod_available || (WC()->customer && WC()->customer->get_billing_country() != 'AE')) {
- unset($available_gateways['cod']);
- }
- }
- return $available_gateways;
- }, 200);
- // Vendor Setting
- add_filter('wcfm_marketplace_settings_fields_billing', function ($vendor_billing_fields, $vendor_id) {
- $vendor_data = get_user_meta($vendor_id, 'wcfmmp_profile_settings', true);
- if (!$vendor_data) {
- $vendor_data = array();
- }
- $is_cod_enabled = isset($vendor_data['payment']['wcfm_cod_enabled']) ? 'yes' : 'no';
- $vendor_wcfm_cod_enabled_fields = array(
- 'wcfm_cod_enabled' => array(
- 'label' => __('COD Enable for Checkout', 'wc-frontend-manager'),
- 'name' => 'payment[wcfm_cod_enabled]',
- 'type' => 'checkbox',
- 'class' => 'wcfm-checkbox wcfm_ele',
- 'label_class' => 'wcfm_title wcfm_ele checkbox_title',
- 'value' => 'yes',
- 'dfvalue' => $is_cod_enabled
- ),
- );
- $vendor_billing_fields = array_merge($vendor_wcfm_cod_enabled_fields, $vendor_billing_fields);
- return $vendor_billing_fields;
- }, 50, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement