Advertisement
wclovers

Untitled

May 5th, 2023
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.95 KB | None | 0 0
  1. add_action('end_wcfm_vendor_settings', function ($vendor_id) {
  2.     global $WCFM, $WCFMmp;
  3.     $wcfm_min_order_amt     = get_user_meta($vendor_id, '_wcfm_min_order_amt', true);
  4.     ?>
  5.     <!– collapsible –>
  6.     <div class="page_collapsible" id="wcfm_settings_form_min_order_amount_head">
  7.         <label class="wcfmfa fa-cart-plus"></label>
  8.         <?php _e('Mindestbestellwert Versand', 'wc-frontend-manager'); ?><span></span>
  9.     </div>
  10.     <div class="wcfm-container">
  11.         <div id="wcfm_settings_form_vendor_invoice_expander" class="wcfm-content">
  12.             <?php
  13.             $WCFM->wcfm_fields->wcfm_generate_form_field(array(
  14.                 "_wcfm_min_order_amt" => array('label' => __('Mindestbestellwert bei Versand', 'wc-frontend-manager'), 'type' => 'select', 'options' => array('' => 0, '29' => '29', '39' => '39', '49' => '49', '79' => '79', '99' => '99'), 'class' => 'wcfm-select wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_min_order_amt),
  15.             ));
  16.             ?>
  17.         </div>
  18.     </div>
  19.     <div class="wcfm_clearfix"></div>
  20.     <!– end collapsible –>
  21.     <?php
  22. }, 500);
  23. add_filter('wcfm_marketplace_settings_fields_general', function ($setting_fields, $vendor_id) {
  24.     if (!wcfm_is_vendor()) {
  25.         $wcfm_min_order_amt     = get_user_meta($vendor_id, '_wcfm_min_order_amt', true);
  26.         $wcfm_min_order_amt_field = array(
  27.             "_wcfm_min_order_amt" => array('label' => __('Mindestbestellwert bei Versand', 'wc-frontend-manager'), 'type' => 'select', 'options' => array('' => 0, '29' => '29', '39' => '39', '49' => '49', '79' => '79', '99' => '99'), 'class' => 'wcfm-select wcfm_ele', 'label_class' => 'wcfm_title wcfm_ele', 'value' => $wcfm_min_order_amt),
  28.         );
  29.         $setting_fields = array_merge($wcfm_min_order_amt_field, $setting_fields);
  30.     }
  31.     return $setting_fields;
  32. }, 50, 2);
  33. add_action('wcfm_vendor_settings_update', function ($vendor_id, $wcfm_settings_form) {
  34.     global $WCFM, $WCFMmp;
  35.     if (isset($wcfm_settings_form['_wcfm_min_order_amt'])) {
  36.         $wcfm_min_order_amt = $wcfm_settings_form['_wcfm_min_order_amt'];
  37.         update_user_meta($vendor_id, '_wcfm_min_order_amt',  $wcfm_min_order_amt);
  38.     }
  39. }, 500, 2);
  40. add_action('woocommerce_check_cart_items', function () {
  41.     global $WCFM, $WCFMmp;
  42.     $return = true;
  43.     $flag = 0;
  44.     if (is_cart() || is_checkout()) {
  45.         $vendor_wise_cart_total = array();
  46.         $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
  47.         $skip_products = ['520609'];
  48.         $skip_vendors = [];
  49.  
  50.         foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
  51.             $cart_product_id = $cart_item['product_id'];
  52.             $_product = wc_get_product($cart_product_id);
  53.             if ($_product->get_type() == 'appointment') { //check your required product type
  54.                 $flag = 1;
  55.                 break;
  56.             }
  57.             $cart_product = get_post($cart_product_id);
  58.  
  59.             if (in_array($cart_product_id, $skip_products)) {
  60.                 if (!in_array($cart_product->post_author, $skip_vendors)) {
  61.                     $skip_vendors[] = $cart_product->post_author;
  62.                 }
  63.             }
  64.  
  65.             if (!isset($vendor_wise_cart_total[$cart_product->post_author])) $vendor_wise_cart_total[$cart_product->post_author] = 0;
  66.             $vendor_wise_cart_total[$cart_product->post_author] += $cart_item['line_total'];
  67.         }
  68.         if (!empty($vendor_wise_cart_total)) {
  69.             foreach ($vendor_wise_cart_total as $vendor_id => $cart_total) {
  70.                 if (wcfm_is_vendor($vendor_id) && !in_array($vendor_id, $skip_vendors)) {
  71.                     if (!empty($chosen_shipping_methods) && isset($chosen_shipping_methods[$vendor_id])) {
  72.                         $ship_method_id = $chosen_shipping_methods[$vendor_id];
  73.                         $ship_id = explode(":", $ship_method_id, 2);
  74.                         $ship_id = $ship_id[0];
  75.                         if ($ship_id != 'local_pickup') {
  76.                             $wcfm_min_order_amt = get_user_meta($vendor_id, '_wcfm_min_order_amt', true);
  77.                             if ($wcfm_min_order_amt && ($wcfm_min_order_amt > $cart_total) && $flag != 1) {
  78.                                 wc_clear_notices();
  79.                                 $vendor_label = $WCFM->wcfm_vendor_support->wcfm_get_vendor_store_by_vendor($vendor_id) . ' ' . apply_filters('wcfm_sold_by_label', $vendor_id, __('Store', 'wc-frontend-manager'));
  80.                                 wc_add_notice(sprintf(__("%s Der Mindestbestellwert des Farmers liegt bei %s. Bestimmt findest du noch etwas Schönes.", "wc-frontend-manager"), $vendor_label, wc_price($wcfm_min_order_amt)), 'error');
  81.                                 $return = false;
  82.                                 break;
  83.                             }
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.     }
  90.     return $return;
  91. }, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement