Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('end_wcfm_vendor_settings', function ($vendor_id) {
- global $WCFM, $WCFMmp;
- $wcfm_min_order_amt = get_user_meta($vendor_id, '_wcfm_min_order_amt', true);
- ?>
- <!– collapsible –>
- <div class="page_collapsible" id="wcfm_settings_form_min_order_amount_head">
- <label class="wcfmfa fa-cart-plus"></label>
- <?php _e('Mindestbestellwert Versand', 'wc-frontend-manager'); ?><span></span>
- </div>
- <div class="wcfm-container">
- <div id="wcfm_settings_form_vendor_invoice_expander" class="wcfm-content">
- <?php
- $WCFM->wcfm_fields->wcfm_generate_form_field(array(
- "_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),
- ));
- ?>
- </div>
- </div>
- <div class="wcfm_clearfix"></div>
- <!– end collapsible –>
- <?php
- }, 500);
- add_filter('wcfm_marketplace_settings_fields_general', function ($setting_fields, $vendor_id) {
- if (!wcfm_is_vendor()) {
- $wcfm_min_order_amt = get_user_meta($vendor_id, '_wcfm_min_order_amt', true);
- $wcfm_min_order_amt_field = array(
- "_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),
- );
- $setting_fields = array_merge($wcfm_min_order_amt_field, $setting_fields);
- }
- return $setting_fields;
- }, 50, 2);
- add_action('wcfm_vendor_settings_update', function ($vendor_id, $wcfm_settings_form) {
- global $WCFM, $WCFMmp;
- if (isset($wcfm_settings_form['_wcfm_min_order_amt'])) {
- $wcfm_min_order_amt = $wcfm_settings_form['_wcfm_min_order_amt'];
- update_user_meta($vendor_id, '_wcfm_min_order_amt', $wcfm_min_order_amt);
- }
- }, 500, 2);
- add_action('woocommerce_check_cart_items', function () {
- global $WCFM, $WCFMmp;
- $return = true;
- $flag = 0;
- if (is_cart() || is_checkout()) {
- $vendor_wise_cart_total = array();
- $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
- $skip_products = ['520609'];
- $skip_vendors = [];
- foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
- $cart_product_id = $cart_item['product_id'];
- $_product = wc_get_product($cart_product_id);
- if ($_product->get_type() == 'appointment') { //check your required product type
- $flag = 1;
- break;
- }
- $cart_product = get_post($cart_product_id);
- if (in_array($cart_product_id, $skip_products)) {
- if (!in_array($cart_product->post_author, $skip_vendors)) {
- $skip_vendors[] = $cart_product->post_author;
- }
- }
- if (!isset($vendor_wise_cart_total[$cart_product->post_author])) $vendor_wise_cart_total[$cart_product->post_author] = 0;
- $vendor_wise_cart_total[$cart_product->post_author] += $cart_item['line_total'];
- }
- if (!empty($vendor_wise_cart_total)) {
- foreach ($vendor_wise_cart_total as $vendor_id => $cart_total) {
- if (wcfm_is_vendor($vendor_id) && !in_array($vendor_id, $skip_vendors)) {
- if (!empty($chosen_shipping_methods) && isset($chosen_shipping_methods[$vendor_id])) {
- $ship_method_id = $chosen_shipping_methods[$vendor_id];
- $ship_id = explode(":", $ship_method_id, 2);
- $ship_id = $ship_id[0];
- if ($ship_id != 'local_pickup') {
- $wcfm_min_order_amt = get_user_meta($vendor_id, '_wcfm_min_order_amt', true);
- if ($wcfm_min_order_amt && ($wcfm_min_order_amt > $cart_total) && $flag != 1) {
- wc_clear_notices();
- $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'));
- 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');
- $return = false;
- break;
- }
- }
- }
- }
- }
- }
- }
- return $return;
- }, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement