• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wc_format_list_of_items函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wc_format_list_of_items函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_format_list_of_items函数的具体用法?PHP wc_format_list_of_items怎么用?PHP wc_format_list_of_items使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wc_format_list_of_items函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: wc_add_to_cart_message

/**
 * Add to cart messages.
 *
 * @access public
 * @param int|array $products
 * @param bool $show_qty Should qty's be shown? Added in 2.6.0
 */
function wc_add_to_cart_message($products, $show_qty = false)
{
    $titles = array();
    $count = 0;
    if (!is_array($products)) {
        $products = array($products);
        $show_qty = false;
    }
    if (!$show_qty && !is_array($products)) {
        $products = array_fill_keys(array_values($products), 1);
    }
    foreach ($products as $product_id => $qty) {
        $titles[] = ($qty > 1 ? absint($qty) . ' × ' : '') . sprintf(_x('“%s”', 'Item name in quotes', 'woocommerce'), strip_tags(get_the_title($product_id)));
        $count += $qty;
    }
    $titles = array_filter($titles);
    $added_text = sprintf(_n('%s has been added to your cart.', '%s have been added to your cart.', $count, 'woocommerce'), wc_format_list_of_items($titles));
    // Output success messages
    if ('yes' === get_option('woocommerce_cart_redirect_after_add')) {
        $return_to = apply_filters('woocommerce_continue_shopping_redirect', wp_get_raw_referer() ? wp_validate_redirect(wp_get_raw_referer(), false) : wc_get_page_permalink('shop'));
        $message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url($return_to), esc_html__('Continue Shopping', 'woocommerce'), esc_html($added_text));
    } else {
        $message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url(wc_get_page_permalink('cart')), esc_html__('View Cart', 'woocommerce'), esc_html($added_text));
    }
    wc_add_notice(apply_filters('wc_add_to_cart_message', $message, $product_id));
}
开发者ID:coderkevin,项目名称:woocommerce,代码行数:33,代码来源:wc-cart-functions.php


示例2: wc_add_to_cart_message

/**
 * Add to cart messages.
 *
 * @access public
 * @param int|array $product_id
 */
function wc_add_to_cart_message($product_id)
{
    if (is_array($product_id)) {
        $titles = array();
        foreach ($product_id as $id) {
            $titles[] = get_the_title($id);
        }
        $added_text = sprintf(__('Added %s to your cart.', 'woocommerce'), wc_format_list_of_items($titles));
    } else {
        $added_text = sprintf(__('&quot;%s&quot; was successfully added to your cart.', 'woocommerce'), get_the_title($product_id));
    }
    // Output success messages
    if (get_option('woocommerce_cart_redirect_after_add') == 'yes') {
        $return_to = apply_filters('woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url());
        $message = sprintf('<p class="[ text-center ]"> %3$s <br /><br /><a href="%s" class="[ button button--primary ][ no-margin ][ pull-none ][ wc-forward ]">%s</a></p>', $return_to, __('Continue Shopping', 'woocommerce'), $added_text);
    } else {
        $message = sprintf('<p class="[ text-center ]"> %3$s <br /><br /><a href="%s" class="[ button button--primary ][ no-margin ][ pull-none ][ wc-forward ]">%s</a></p>', wc_get_page_permalink('cart'), __('View Cart', 'woocommerce'), $added_text);
    }
    wc_add_notice(apply_filters('wc_add_to_cart_message', $message, $product_id));
}
开发者ID:pcuervo,项目名称:ur-imprint,代码行数:26,代码来源:wc-cart-functions.php


示例3: wc_add_to_cart_message

/**
 * Add to cart messages.
 *
 * @access public
 * @param int|array $product_id
 */
function wc_add_to_cart_message($product_id)
{
    $titles = array();
    if (is_array($product_id)) {
        foreach ($product_id as $id) {
            $titles[] = get_the_title($id);
        }
    } else {
        $titles[] = get_the_title($product_id);
    }
    $titles = array_filter($titles);
    $added_text = sprintf(_n('%s has been added to your cart.', '%s have been added to your cart.', sizeof($titles), 'woocommerce'), wc_format_list_of_items($titles));
    // Output success messages
    if ('yes' === get_option('woocommerce_cart_redirect_after_add')) {
        $return_to = apply_filters('woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url());
        $message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url($return_to), esc_html__('Continue Shopping', 'woocommerce'), esc_html($added_text));
    } else {
        $message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', esc_url(wc_get_page_permalink('cart')), esc_html__('View Cart', 'woocommerce'), esc_html($added_text));
    }
    wc_add_notice(apply_filters('wc_add_to_cart_message', $message, $product_id));
}
开发者ID:randyriolis,项目名称:woocommerce,代码行数:27,代码来源:wc-cart-functions.php


示例4: add_to_cart_handler_variable

 /**
  * Handle adding variable products to the cart.
  * @since 2.4.6 Split from add_to_cart_action
  * @param int $product_id
  * @return bool success or not
  */
 private static function add_to_cart_handler_variable($product_id)
 {
     $adding_to_cart = wc_get_product($product_id);
     $variation_id = empty($_REQUEST['variation_id']) ? '' : absint($_REQUEST['variation_id']);
     $quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
     $missing_attributes = array();
     $variations = array();
     $attributes = $adding_to_cart->get_attributes();
     // If no variation ID is set, attempt to get a variation ID from posted attributes.
     if (empty($variation_id)) {
         $variation_id = $adding_to_cart->get_matching_variation(wp_unslash($_POST));
     }
     $variation = wc_get_product($variation_id);
     // Validate the attributes.
     try {
         if (empty($variation_id)) {
             throw new Exception(__('Please choose product options&hellip;', 'woocommerce'));
         }
         foreach ($attributes as $attribute) {
             if (!$attribute['is_variation']) {
                 continue;
             }
             $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
             if (isset($_REQUEST[$taxonomy])) {
                 // Get value from post data
                 if ($attribute['is_taxonomy']) {
                     // Don't use wc_clean as it destroys sanitized characters
                     $value = sanitize_title(stripslashes($_REQUEST[$taxonomy]));
                 } else {
                     $value = wc_clean(stripslashes($_REQUEST[$taxonomy]));
                 }
                 // Get valid value from variation
                 $valid_value = isset($variation->variation_data[$taxonomy]) ? $variation->variation_data[$taxonomy] : '';
                 // Allow if valid or show error.
                 if ('' === $valid_value || $valid_value === $value) {
                     $variations[$taxonomy] = $value;
                 } else {
                     throw new Exception(sprintf(__('Invalid value posted for %s', 'woocommerce'), wc_attribute_label($attribute['name'])));
                 }
             } else {
                 $missing_attributes[] = wc_attribute_label($attribute['name']);
             }
         }
         if (!empty($missing_attributes)) {
             throw new Exception(sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'woocommerce'), wc_format_list_of_items($missing_attributes)));
         }
     } catch (Exception $e) {
         wc_add_notice($e->getMessage(), 'error');
         return false;
     }
     // Add to cart validation
     $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations);
     if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations) !== false) {
         wc_add_to_cart_message(array($product_id => $quantity), true);
         return true;
     }
     return false;
 }
开发者ID:johnulist,项目名称:woocommerce,代码行数:64,代码来源:class-wc-form-handler.php


示例5: add_to_cart_action

 /**
  * Add to cart action
  *
  * Checks for a valid request, does validation (via hooks) and then redirects if valid.
  *
  * @param bool $url (default: false)
  */
 public static function add_to_cart_action($url = false)
 {
     if (empty($_REQUEST['add-to-cart']) || !is_numeric($_REQUEST['add-to-cart'])) {
         return;
     }
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_REQUEST['add-to-cart']));
     $was_added_to_cart = false;
     $added_to_cart = array();
     $adding_to_cart = wc_get_product($product_id);
     $add_to_cart_handler = apply_filters('woocommerce_add_to_cart_handler', $adding_to_cart->product_type, $adding_to_cart);
     // Check if the product is published
     if ('publish' !== $adding_to_cart->post->post_status) {
         wc_add_notice(__('Sorry, this product is unavailable.', 'woocommerce'), 'error');
         return;
     }
     // Variable product handling
     if ('variable' === $add_to_cart_handler) {
         $variation_id = empty($_REQUEST['variation_id']) ? '' : absint($_REQUEST['variation_id']);
         $quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
         $missing_attributes = array();
         $variations = array();
         $attributes = $adding_to_cart->get_attributes();
         $variation = wc_get_product($variation_id);
         // Verify all attributes
         foreach ($attributes as $attribute) {
             if (!$attribute['is_variation']) {
                 continue;
             }
             $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
             if (isset($_REQUEST[$taxonomy])) {
                 // Get value from post data
                 if ($attribute['is_taxonomy']) {
                     // Don't use wc_clean as it destroys sanitized characters
                     $value = sanitize_title(stripslashes($_REQUEST[$taxonomy]));
                 } else {
                     $value = wc_clean(stripslashes($_REQUEST[$taxonomy]));
                 }
                 // Get valid value from variation
                 $valid_value = $variation->variation_data[$taxonomy];
                 // Allow if valid
                 if ('' === $valid_value || $valid_value === $value) {
                     // Pre 2.4 handling where 'slugs' were saved instead of the full text attribute
                     if (!$attribute['is_taxonomy']) {
                         if ($value === sanitize_title($value) && version_compare(get_post_meta($product_id, '_product_version', true), '2.4.0', '<')) {
                             $text_attributes = wc_get_text_attributes($attribute['value']);
                             foreach ($text_attributes as $text_attribute) {
                                 if (sanitize_title($text_attribute) === $value) {
                                     $value = $text_attribute;
                                     break;
                                 }
                             }
                         }
                     }
                     $variations[$taxonomy] = $value;
                     continue;
                 }
             } else {
                 $missing_attributes[] = wc_attribute_label($attribute['name']);
             }
         }
         if ($missing_attributes) {
             wc_add_notice(sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'woocommerce'), wc_format_list_of_items($missing_attributes)), 'error');
             return;
         } elseif (empty($variation_id)) {
             wc_add_notice(__('Please choose product options&hellip;', 'woocommerce'), 'error');
             return;
         } else {
             // Add to cart validation
             $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations);
             if ($passed_validation) {
                 if (WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations) !== false) {
                     wc_add_to_cart_message($product_id);
                     $was_added_to_cart = true;
                     $added_to_cart[] = $product_id;
                 }
             }
         }
         // Grouped Products
     } elseif ('grouped' === $add_to_cart_handler) {
         if (!empty($_REQUEST['quantity']) && is_array($_REQUEST['quantity'])) {
             $quantity_set = false;
             foreach ($_REQUEST['quantity'] as $item => $quantity) {
                 if ($quantity <= 0) {
                     continue;
                 }
                 $quantity_set = true;
                 // Add to cart validation
                 $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $item, $quantity);
                 if ($passed_validation) {
                     if (WC()->cart->add_to_cart($item, $quantity) !== false) {
                         $was_added_to_cart = true;
                         $added_to_cart[] = $item;
                     }
//.........这里部分代码省略.........
开发者ID:nightbook,项目名称:woocommerce,代码行数:101,代码来源:class-wc-form-handler.php


示例6: add_to_cart_handler_variable

 /**
  * Handle adding variable products to the cart
  * @since 2.4.6 Split from add_to_cart_action
  * @param int $product_id
  * @return bool success or not
  */
 private static function add_to_cart_handler_variable($product_id)
 {
     $adding_to_cart = wc_get_product($product_id);
     $variation_id = empty($_REQUEST['variation_id']) ? '' : absint($_REQUEST['variation_id']);
     $quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
     $missing_attributes = array();
     $variations = array();
     $attributes = $adding_to_cart->get_attributes();
     $variation = wc_get_product($variation_id);
     // Verify all attributes
     foreach ($attributes as $attribute) {
         if (!$attribute['is_variation']) {
             continue;
         }
         $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
         if (isset($_REQUEST[$taxonomy])) {
             // Get value from post data
             if ($attribute['is_taxonomy']) {
                 // Don't use wc_clean as it destroys sanitized characters
                 $value = sanitize_title(stripslashes($_REQUEST[$taxonomy]));
             } else {
                 $value = wc_clean(stripslashes($_REQUEST[$taxonomy]));
             }
             // Get valid value from variation
             $valid_value = $variation->variation_data[$taxonomy];
             // Allow if valid
             if ('' === $valid_value || $valid_value === $value) {
                 $variations[$taxonomy] = $value;
                 continue;
             }
         } else {
             $missing_attributes[] = wc_attribute_label($attribute['name']);
         }
     }
     if ($missing_attributes) {
         wc_add_notice(sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'woocommerce'), wc_format_list_of_items($missing_attributes)), 'error');
     } elseif (empty($variation_id)) {
         wc_add_notice(__('Please choose product options&hellip;', 'woocommerce'), 'error');
     } else {
         // Add to cart validation
         $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations);
         if ($passed_validation && WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variations) !== false) {
             wc_add_to_cart_message($product_id);
             return true;
         }
     }
     return false;
 }
开发者ID:bear12345678,项目名称:keylessoption,代码行数:54,代码来源:class-wc-form-handler11.php


示例7: wc_cp_validation


//.........这里部分代码省略.........
                         } else {
                             // Get value from post data.
                             $value = sanitize_title(trim(stripslashes($_REQUEST['wccp_' . $taxonomy][$component_id])));
                         }
                         // Get valid value from variation.
                         $valid_value = $variation_data[$taxonomy];
                         // Allow if valid.
                         if ($valid_value === '' || $valid_value === $value) {
                             continue;
                         }
                     } elseif (isset($cart_item_data['composite_data'][$component_id]['attributes'][$taxonomy]) && isset($cart_item_data['composite_data'][$component_id]['variation_id']) && $order_again) {
                         if (WC_CP_Core_Compatibility::is_wc_version_gte_2_4()) {
                             // Get value from post data.
                             if ($attribute['is_taxonomy']) {
                                 $value = sanitize_title(stripslashes($cart_item_data['composite_data'][$component_id]['attributes'][$taxonomy]));
                             } else {
                                 $value = wc_clean(stripslashes($cart_item_data['composite_data'][$component_id]['attributes'][$taxonomy]));
                             }
                         } else {
                             // Get value from post data.
                             $value = sanitize_title(trim(stripslashes($cart_item_data['composite_data'][$component_id]['attributes'][$taxonomy])));
                         }
                         $valid_value = $variation_data[$taxonomy];
                         if ($valid_value === '' || $valid_value === $value) {
                             continue;
                         }
                     } else {
                         $missing_attributes[] = wc_attribute_label($attribute['name']);
                     }
                     $all_set = false;
                 }
                 if (!$all_set) {
                     if ($missing_attributes && WC_CP_Core_Compatibility::is_wc_version_gte_2_3()) {
                         $required_fields_notice = sprintf(_n('%1$s is a required &quot;%2$s&quot; field', '%1$s are required &quot;%2$s&quot; fields', sizeof($missing_attributes), 'woocommerce-composite-products'), wc_format_list_of_items($missing_attributes), apply_filters('woocommerce_composite_component_title', $composite_data[$component_id]['title'], $component_id, $product_id));
                         wc_add_notice(sprintf(__('This &quot;%1$s&quot; configuration cannot be added to the cart. %2$s.', 'woocommerce-composite-products'), get_the_title($product_id), $required_fields_notice), 'error');
                         return false;
                     } else {
                         wc_add_notice(sprintf(__('This &quot;%1$s&quot; configuration cannot be added to the cart. Please choose &quot;%2$s&quot; options&hellip;', 'woocommerce-composite-products'), get_the_title($product_id), apply_filters('woocommerce_composite_component_title', $composite_data[$component_id]['title'], $component_id, $product_id)), 'error');
                         return false;
                     }
                 }
             } elseif ($composited_product_type === 'simple') {
                 // Add item for validation.
                 $composited_stock->add_item($composited_product_id, false, $quantity);
             } else {
                 // Add item for validation.
                 $composited_stock->add_item($composited_product_id, false, $quantity);
             }
             if (!apply_filters('woocommerce_composite_component_add_to_cart_validation', true, $product_id, $component_id, $composited_product_id, $quantity, $cart_item_data)) {
                 return false;
             }
             // Allow composited products to add extra items to the stock manager.
             $composited_stock->add_stock(apply_filters('woocommerce_composite_component_associated_stock', '', $product_id, $component_id, $composited_product_id, $quantity));
         }
         /*
          * Stock Validation.
          */
         if (false === $composited_stock->validate_stock()) {
             return false;
         }
         /*
          * Scenarios Validation.
          */
         $scenario_data = get_post_meta($product_id, '_bto_scenario_data', true);
         $scenario_data = apply_filters('woocommerce_composite_scenario_meta', $scenario_data, $composite);
         $posted_scenarios = !empty($_POST['wccp_active_scenarios']) ? array_map('wc_clean', explode(',', $_POST['wccp_active_scenarios'])) : array();
开发者ID:alexbaron50,项目名称:Rockk3rs-Lab-Test,代码行数:67,代码来源:class-wc-cp-cart.php


示例8: test_wc_format_list_of_items

 /**
  * Test wc_format_list_of_items().
  *
  * @since 2.4
  */
 public function test_wc_format_list_of_items()
 {
     $items = array('Title 1', 'Title 2');
     $this->assertEquals('Title 1 and Title 2', wc_format_list_of_items($items));
 }
开发者ID:coderkevin,项目名称:woocommerce,代码行数:10,代码来源:functions.php


示例9: add_to_cart_handler_variable

 /**
  * Custom add to cart handler for variable products
  *
  * Based on function add_to_cart_handler_variable( $product_id ) from
  * <install_dir>/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php
  * but using $url as argument.Therefore we use the initial bits from
  * add_to_cart_action( $url ).
  *
  * @param string    $url   Add to cart url (e.g. https://www.yourdomain.com/?add-to-cart=123&quantity=1&variation_id=117&attribute_size=Small&attribute_color=Black )
  */
 public function add_to_cart_handler_variable($url)
 {
     // From add_to_cart_action( $url )
     if (empty($_REQUEST['add-to-cart']) || !is_numeric($_REQUEST['add-to-cart'])) {
         return;
     }
     $product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_REQUEST['add-to-cart']));
     $was_added_to_cart = false;
     $adding_to_cart = wc_get_product($product_id);
     if (!$adding_to_cart) {
         return;
     }
     // End: From add_to_cart_action( $url )
     // From add_to_cart_handler_variable( $product_id )
     $variation_id = empty($_REQUEST['variation_id']) ? '' : absint($_REQUEST['variation_id']);
     $quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
     $missing_attributes = array();
     $variations = array();
     $attributes = $adding_to_cart->get_attributes();
     // If no variation ID is set, attempt to get a variation ID from posted attributes.
     if (empty($variation_id)) {
         $variation_id = $adding_to_cart->get_matching_variation(wp_unslash($_POST));
     }
     /**
      * Custom code to check if a translation of the product is already in the
      * cart,* and in that case, replace the variation being added to the cart
      * by the respective translation in the language of the product already
      * in the cart.
      * NOTE: The product_id is filtered by $this->add_to_cart() and holds the
      * id of the product translation, if one exists in the cart.
      */
     if ($product_id != absint($_REQUEST['add-to-cart'])) {
         // There is a translation of the product already in the cart:
         // Get the language of the product in the cart
         $lang = pll_get_post_language($product_id);
         // Get the respective variation in the language of the product in the cart
         $variation = $this->get_variation_translation($variation_id, $lang);
         $variation_id = $variation->variation_id;
     } else {
         $variation = wc_get_product($variation_id);
     }
     /**
      * End of custom code.
      */
     //$variation = wc_get_product( $variation_id );
     // Verify all attributes
     foreach ($attributes as $attribute) {
         if (!$attribute['is_variation']) {
             continue;
         }
         $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
         if (isset($_REQUEST[$taxonomy])) {
             // Get value from post data
             if ($attribute['is_taxonomy']) {
                 // Don't use wc_clean as it destroys sanitized characters
                 $value = sanitize_title(stripslashes($_REQUEST[$taxonomy]));
                 /**
                  * Custom code to check if a translation of the product is already in the cart,
                  * and in that case, replace the variation attribute being added to the cart by
                  * the respective translation in the language of the product already in the cart
                  * NOTE: The product_id is filtered by $this->add_to_cart() and holds the id of
                  * the product translation, if one exists in the cart.
                  */
                 if ($product_id != absint($_REQUEST['add-to-cart'])) {
                     // Get the translation of the term
                     $term = get_term_by('slug', $value, $attribute['name']);
                     $_term = get_term_by('id', pll_get_term(absint($term->term_id), $lang), $attribute['name']);
                     if ($_term) {
                         $value = $_term->slug;
                     }
                 }
                 /**
                  * End of custom code.
                  */
             } else {
                 $value = wc_clean(stripslashes($_REQUEST[$taxonomy]));
             }
             // Get valid value from variation
             $valid_value = isset($variation->variation_data[$taxonomy]) ? $variation->variation_data[$taxonomy] : '';
             // Allow if valid
             if ('' === $valid_value || $valid_value === $value) {
                 $variations[$taxonomy] = $value;
                 continue;
             }
         } else {
             $missing_attributes[] = wc_attribute_label($attribute['name']);
         }
     }
     if (!empty($missing_attributes)) {
         wc_add_notice(sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'woocommerce'), wc_format_list_of_items($missing_attributes)), 'error');
//.........这里部分代码省略.........
开发者ID:decarvalhoaa,项目名称:woopoly,代码行数:101,代码来源:Cart.php


示例10: woo_bundles_validation


//.........这里部分代码省略.........
             // Validate variation id.
             if ($bundled_product_type === 'variable' || $bundled_product_type === 'variable-subscription') {
                 $variation_id = '';
                 if (isset($cart_item_data['stamp'][$bundled_item_id]['variation_id']) && $order_again) {
                     $variation_id = $cart_item_data['stamp'][$bundled_item_id]['variation_id'];
                 } elseif (isset($_REQUEST[apply_filters('woocommerce_product_bundle_field_prefix', '', $product_id) . 'bundle_variation_id_' . $bundled_item_id])) {
                     $variation_id = $_REQUEST[apply_filters('woocommerce_product_bundle_field_prefix', '', $product_id) . 'bundle_variation_id_' . $bundled_item_id];
                 }
                 if ($variation_id && is_numeric($variation_id) && $variation_id > 1) {
                     if (get_post_meta($variation_id, '_price', true) === '') {
                         wc_add_notice(sprintf(__('&quot;%1$s&quot; cannot be added to the cart. The selected variation of &quot;%2$s&quot; cannot be purchased.', 'woocommerce-product-bundles'), get_the_title($product_id), $bundled_item->product->get_title()), 'error');
                         return false;
                     }
                     // Add item for validation.
                     $bundled_stock->add_item($id, $variation_id, $quantity);
                 }
                 // Verify all attributes for the variable product were set.
                 $bundled_variation = wc_get_product($variation_id);
                 $attributes = (array) maybe_unserialize(get_post_meta($id, '_product_attributes', true));
                 $variation_data = array();
                 $missing_attributes = array();
                 $all_set = true;
                 if ($bundled_variation) {
                     $variation_data = $bundled_variation->variation_data;
                     // Verify all attributes.
                     foreach ($attributes as $attribute) {
                         if (!$attribute['is_variation']) {
                             continue;
                         }
                         $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
                         if (!empty($_REQUEST[apply_filters('woocommerce_product_bundle_field_prefix', '', $product_id) . 'bundle_' . $taxonomy . '_' . $bundled_item_id])) {
                             if (WC_PB_Core_Compatibility::is_wc_version_gte_2_4()) {
                                 // Get value from post data.
                                 if ($attribute['is_taxonomy']) {
                                     $value = sanitize_title(stripslashes($_REQUEST[apply_filters('woocommerce_product_bundle_field_prefix', '', $product_id) . 'bundle_' . $taxonomy . '_' . $bundled_item_id]));
                                 } else {
                                     $value = wc_clean(stripslashes($_REQUEST[apply_filters('woocommerce_product_bundle_field_prefix', '', $product_id) . 'bundle_' . $taxonomy . '_' . $bundled_item_id]));
                                 }
                             } else {
                                 // Get value from post data.
                                 $value = sanitize_title(trim(stripslashes($_REQUEST[apply_filters('woocommerce_product_bundle_field_prefix', '', $product_id) . 'bundle_' . $taxonomy . '_' . $bundled_item_id])));
                             }
                             // Get valid value from variation.
                             $valid_value = $variation_data[$taxonomy];
                             // Allow if valid
                             if ($valid_value === '' || $valid_value === $value) {
                                 continue;
                             }
                         } elseif (isset($cart_item_data['stamp'][$bundled_item_id]['attributes'][$taxonomy]) && isset($cart_item_data['stamp'][$bundled_item_id]['variation_id']) && $order_again) {
                             if (WC_PB_Core_Compatibility::is_wc_version_gte_2_4()) {
                                 // Get value from post data
                                 if ($attribute['is_taxonomy']) {
                                     $value = sanitize_title(stripslashes($cart_item_data['stamp'][$bundled_item_id]['attributes'][$taxonomy]));
                                 } else {
                                     $value = wc_clean(stripslashes($cart_item_data['stamp'][$bundled_item_id]['attributes'][$taxonomy]));
                                 }
                             } else {
                                 // Get value from post data
                                 $value = sanitize_title(trim(stripslashes($cart_item_data['stamp'][$bundled_item_id]['attributes'][$taxonomy])));
                             }
                             $valid_value = $variation_data[$taxonomy];
                             if ($valid_value === '' || $valid_value === $value) {
                                 continue;
                             }
                         } else {
                             $missing_attributes[] = wc_attribute_label($attribute['name']);
                         }
                         $all_set = false;
                     }
                 } else {
                     $all_set = false;
                 }
                 if (!$all_set) {
                     if ($missing_attributes && WC_PB_Core_Compatibility::is_wc_version_gte_2_3()) {
                         $required_fields_notice = sprintf(_n('%1$s is a required &quot;%2$s&quot; field', '%1$s are required &quot;%2$s&quot; fields', sizeof($missing_attributes), 'woocommerce-product-bundles'), wc_format_list_of_items($missing_attributes), $bundled_item->product->get_title());
                         wc_add_notice(sprintf(__('&quot;%1$s&quot; cannot be added to the cart. %2$s.', 'woocommerce-product-bundles'), get_the_title($product_id), $required_fields_notice), 'error');
                         return false;
                     } else {
                         wc_add_notice(sprintf(__('&quot;%1$s&quot; cannot be added to the cart. Please choose &quot;%2$s&quot; options&hellip;', 'woocommerce-product-bundles'), get_the_title($product_id), $bundled_item->product->get_title()), 'error');
                         return false;
                     }
                 }
             } elseif ($bundled_product_type === 'simple' || $bundled_product_type === 'subscription') {
                 // Add item for validation.
                 $bundled_stock->add_item($id, false, $quantity);
             }
             if (!apply_filters('woocommerce_bundled_item_add_to_cart_validation', true, $product, $bundled_item, $quantity, $variation_id)) {
                 return false;
             }
         }
         // Check stock for stock-managed bundled items.
         // If out of stock, don't proceed.
         if (false === apply_filters('woocommerce_add_to_cart_bundle_validation', $bundled_stock->validate_stock(), $product_id, $bundled_stock)) {
             return false;
         }
         // Composite Products compatibility.
         WC_PB_Compatibility::$stock_data = $bundled_stock;
     }
     return $add;
 }
开发者ID:alexbaron50,项目名称:Rockk3rs-Lab-Test,代码行数:101,代码来源:class-wc-pb-cart.php


示例11: validate_rule


//.........这里部分代码省略.........
             if ($value) {
                 $max_allowed_tickets = $this->get_open_tour_tickets($product, $value);
                 $tickets_in_cart = $this->get_count_tickets_in_cart($product, $value);
                 if ($tickets_in_cart <= $max_allowed_tickets) {
                     $max_allowed_tickets -= $tickets_in_cart;
                 } else {
                     $max_allowed_tickets = 0;
                 }
                 if ($max_allowed_tickets < 1) {
                     $message_template = $rule_error ? $rule_error : esc_html__('There are no tickets for this date.', 'adventure-tours');
                     $errors[] = $this->format_message($message_template, $value, $field_config);
                 } else {
                     // hack :(
                     $this->set_state($this->make_product_state_key('valid_booking_date', $product), array('max_allowed_tickets' => $max_allowed_tickets));
                 }
             }
             break;
         case 'booking_tickets':
             if ($value && $value > 0) {
                 $date_limit_state = $this->get_state($this->make_product_state_key('valid_booking_date', $product), false);
                 $max_allowed_tickets = $date_limit_state && !empty($date_limit_state['max_allowed_tickets']) ? $date_limit_state['max_allowed_tickets'] : 0;
                 // $max_allowed_tickets = $this->get_open_tour_tickets( $product, '{booking_date}' );
                 if ($max_allowed_tickets > 0 && $value > $max_allowed_tickets) {
                     $message_template = $rule_error ? $rule_error : esc_html(_n('Only 1 ticket is left.', 'Only {left_tickets} tickets are left.', $max_allowed_tickets, 'adventure-tours'));
                     $errors[] = $this->format_message($message_template, $value, $field_config, array('{left_tickets}' => $max_allowed_tickets));
                 }
             }
             break;
         case 'combined_ticket_number':
             if ($value && '0' !== $value) {
                 if (!filter_var($value, FILTER_VALIDATE_INT) || $value < 1) {
                     $message_template = $rule_error ? $rule_error : esc_html__('Check field format.', 'adventure-tours');
                     $errors[] = $this->format_message($message_template, $value, $field_config);
                 }
             }
             break;
         case 'combined_booking_tickets':
             if ($value && $value > 0) {
                 $combined_quantity_state_key = $this->make_product_state_key('combined_quantity_vals', $product);
                 $combined_quantity_values = $this->get_state($combined_quantity_state_key, array());
                 $prev_added_quantity = array_sum($combined_quantity_values);
                 $combined_quantity_values[] = $value;
                 $this->set_state($combined_quantity_state_key, $combined_quantity_values);
                 $date_limit_state = $this->get_state($this->make_product_state_key('valid_booking_date', $product), false);
                 $max_allowed_tickets = $date_limit_state && !empty($date_limit_state['max_allowed_tickets']) ? $date_limit_state['max_allowed_tickets'] : 0;
                 $max_allowed_tickets = $max_allowed_tickets - $prev_added_quantity;
                 if ($max_allowed_tickets > 0) {
                     if ($value > $max_allowed_tickets) {
                         $message_template = $rule_error ? $rule_error : esc_html(_n('Only 1 ticket is left.', 'Only {left_tickets} tickets are left.', $max_allowed_tickets, 'adventure-tours'));
                         $errors[] = $this->format_message($message_template, $value, $field_config, array('{left_tickets}' => $max_allowed_tickets));
                     }
                 } else {
                     $errors[] = esc_html__('There are no more tickets available.', 'adventure-tours');
                 }
             }
             break;
         case 'variation_id':
             if ($value > 0) {
                 $missing_attributes = array();
                 $attributes = $product->get_attributes();
                 $variation = wc_get_product($value);
                 $variations = array();
                 $request_data = $this->get_request_data();
                 // Verify all attributes
                 foreach ($attributes as $attribute) {
                     if (!$attribute['is_variation']) {
                         continue;
                     }
                     $taxonomy = 'attribute_' . sanitize_title($attribute['name']);
                     if (isset($request_data[$taxonomy])) {
                         if ($attribute['is_taxonomy']) {
                             // Don't use wc_clean as it destroys sanitized characters
                             $variation_value = sanitize_title(stripslashes($request_data[$taxonomy]));
                         } else {
                             $variation_value = wc_clean(stripslashes($request_data[$taxonomy]));
                         }
                         // Get valid value from variation
                         $valid_value = $variation->variation_data[$taxonomy];
                         // Allow if valid
                         if ('' === $valid_value || $valid_value === $variation_value) {
                             $variations[$taxonomy] = $variation_value;
                             continue;
                         }
                     } else {
                         $missing_attributes[] = wc_attribute_label($attribute['name']);
                     }
                 }
                 if ($missing_attributes) {
                     $errors[] = sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'adventure-tours'), wc_format_list_of_items($missing_attributes));
                 } elseif (empty($attributes)) {
                     $errors[] = esc_html__('Please choose product options', 'adventure-tours') . '&hellip;';
                 }
                 if (empty($errors)) {
                     $this->set_state($this->make_product_state_key('variations_settings', $product), array('variation_id' => $value, 'variations' => $variations));
                 }
             }
             break;
     }
     return $errors;
 }
开发者ID:j-kenneth,项目名称:Expeero,代码行数:101,代码来源:AtBookingFormBase.php



注:本文中的wc_format_list_of_items函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wc_format_localized_decimal函数代码示例发布时间:2022-05-23
下一篇:
PHP wc_format_hex函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap