本文整理汇总了PHP中wc_attribute_label函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_attribute_label函数的具体用法?PHP wc_attribute_label怎么用?PHP wc_attribute_label使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_attribute_label函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: as_ajax_add_compare_product
function as_ajax_add_compare_product()
{
$product_id = $_REQUEST["product_id"];
$response = array("status" => 0, "message" => "something error");
if (!empty($product_id) && is_numeric($product_id)) {
$product = wc_get_product($product_id);
if (!empty($product)) {
$compare_product = as_get_product_compare();
if (isset($compare_product[$product_id])) {
$response["message"] = __("Product is in compare", AS_DOMAIN) . ' | <a target="_blank" href="' . get_page_link(get_option("as-compare-page-id")) . '">' . __("Go to compare", AS_DOMAIN) . '</a>';
} else {
$product_attrs = $product->get_attributes();
$new_product_attrs = array();
foreach ($product_attrs as $attribute) {
if (empty($attribute['is_visible']) || $attribute['is_taxonomy'] && !taxonomy_exists($attribute['name'])) {
continue;
} else {
if ($attribute['is_taxonomy']) {
$values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
$values = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
} else {
// Convert pipes to commas and display values
$values = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
$values = apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
}
$data_attr = array("name" => $attribute["name"], "title" => wc_attribute_label($attribute['name']), "values" => $values);
$new_product_attrs[$attribute["name"]] = $data_attr;
}
}
$data_product = array("id" => $product_id, "name" => $product->get_title(), "price" => $product->get_price(), "image" => $product->get_image(), "attributes" => $new_product_attrs);
as_save_product_compare($data_product);
$response = array("status" => 1, "message" => "Success", "notice" => __("Product is in compare", AS_DOMAIN) . ' | <a target="_blank" href="' . get_page_link(get_option("as-compare-page-id")) . '">' . __("Go to compare", AS_DOMAIN) . '</a>');
}
} else {
$response["message"] = __("Product does not existed", AS_DOMAIN);
}
} else {
$response["message"] = __("Product does not true", AS_DOMAIN);
}
wp_send_json($response);
}
开发者ID:bibiangel1989,项目名称:vespatour,代码行数:41,代码来源:compare.php
示例2: addAttributeSetToProduct
static function addAttributeSetToProduct()
{
ob_start();
global $wc_product_attributes;
$attributeSetKey = $_POST['key'];
$db = new WCAttributeSetsDb();
$attributeSet = $db->get($attributeSetKey);
if (empty($attributeSet->attributes)) {
die;
}
foreach ($attributeSet->attributes as $attributeKey) {
$thepostid = 0;
$taxonomy = wc_attribute_taxonomy_name($attributeKey);
$i = absint($_POST['i']);
$position = 0;
$metabox_class = array();
$attribute = array('name' => $taxonomy, 'value' => '', 'is_visible' => apply_filters('woocommerce_attribute_default_visibility', 1), 'is_variation' => 0, 'is_taxonomy' => $taxonomy ? 1 : 0);
if ($taxonomy) {
$attribute_taxonomy = $wc_product_attributes[$taxonomy];
$metabox_class[] = 'taxonomy';
$metabox_class[] = $taxonomy;
$attribute_label = wc_attribute_label($taxonomy);
} else {
$attribute_label = '';
}
include WC()->plugin_path() . '/includes/admin/meta-boxes/views/html-product-attribute.php';
}
die;
}
开发者ID:galalaly,项目名称:wc-attribute-sets,代码行数:29,代码来源:class-wc-attribute-sets-woocommerce.php
示例3: get_item_data
function get_item_data($other_data, $cart_item)
{
if (isset($cart_item["wpb_cart_items"])) {
$wpb_cart_items = $cart_item["wpb_cart_items"];
$other_data = array();
$variation_data = $cart_item["variation"];
if (!empty($variation_data)) {
foreach ($variation_data as $attribute => $variation) {
$taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($attribute)));
$term = get_term_by('slug', $variation, $taxonomy);
$attribute_type = WPB_Common_Functions::get_variation_attribute_type($taxonomy);
if ($attribute_type == "carousel") {
$other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $term->name, 'value' => '', 'hidden' => false);
}
if ($attribute_type == "extra") {
$extra_options = $wpb_cart_items["extra"];
$display_label = !empty($extra_options[$taxonomy]) ? $term->name . '(' . $extra_options[$taxonomy] . ')' : $term->name;
$other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $display_label, 'value' => '', 'hidden' => false);
}
if ($attribute_type == "size") {
$size_options = $wpb_cart_items["size"];
$display_label = !empty($size_options[$taxonomy]) ? $size_options[$taxonomy] : "";
$other_data[] = array('name' => wc_attribute_label($taxonomy), 'display' => $display_label, 'value' => '', 'hidden' => false);
}
}
}
}
return $other_data;
}
开发者ID:shirso,项目名称:wc-product-builder,代码行数:29,代码来源:class-product-cart.php
示例4: column_default
/**
* Get column value.
*
* @param mixed $item
* @param string $column_name
*/
public function column_default($item, $column_name)
{
global $product;
if (!$product || $product->id !== $item->id) {
$product = wc_get_product($item->id);
}
switch ($column_name) {
case 'product':
if ($sku = $product->get_sku()) {
echo $sku . ' - ';
}
echo $product->get_title();
// Get variation data
if ($product->is_type('variation')) {
$list_attributes = array();
$attributes = $product->get_variation_attributes();
foreach ($attributes as $name => $attribute) {
$list_attributes[] = wc_attribute_label(str_replace('attribute_', '', $name)) . ': <strong>' . $attribute . '</strong>';
}
echo '<div class="description">' . implode(', ', $list_attributes) . '</div>';
}
break;
case 'parent':
if ($item->parent) {
echo get_the_title($item->parent);
} else {
echo '-';
}
break;
case 'stock_status':
if ($product->is_in_stock()) {
$stock_html = '<mark class="instock">' . __('In stock', 'woocommerce') . '</mark>';
} else {
$stock_html = '<mark class="outofstock">' . __('Out of stock', 'woocommerce') . '</mark>';
}
echo apply_filters('woocommerce_admin_stock_html', $stock_html, $product);
break;
case 'stock_level':
echo $product->get_stock_quantity();
break;
case 'wc_actions':
?>
<p>
<?php
$actions = array();
$action_id = $product->is_type('variation') ? $item->parent : $item->id;
$actions['edit'] = array('url' => admin_url('post.php?post=' . $action_id . '&action=edit'), 'name' => __('Edit', 'woocommerce'), 'action' => "edit");
if ($product->is_visible()) {
$actions['view'] = array('url' => get_permalink($action_id), 'name' => __('View', 'woocommerce'), 'action' => "view");
}
$actions = apply_filters('woocommerce_admin_stock_report_product_actions', $actions, $product);
foreach ($actions as $action) {
printf('<a class="button tips %s" href="%s" data-tip="%s ' . __('product', 'woocommerce') . '">%s</a>', $action['action'], esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name']));
}
?>
</p><?php
break;
}
}
开发者ID:jesusmarket,项目名称:jesusmarket,代码行数:65,代码来源:class-wc-report-stock.php
示例5: display
/**
* Display meta in a formatted list
*
* @access public
* @param bool $flat (default: false)
* @param bool $return (default: false)
* @param string $hideprefix (default: _)
* @return string
*/
public function display($flat = false, $return = false, $hideprefix = '_')
{
if (!empty($this->meta)) {
$meta_list = array();
foreach ($this->meta as $meta_key => $meta_values) {
if (empty($meta_values) || !empty($hideprefix) && substr($meta_key, 0, 1) == $hideprefix) {
continue;
}
foreach ($meta_values as $meta_value) {
// Skip serialised meta
if (is_serialized($meta_value)) {
continue;
}
$attribute_key = urldecode(str_replace('attribute_', '', $meta_key));
// If this is a term slug, get the term's nice name
if (taxonomy_exists($attribute_key)) {
$term = get_term_by('slug', $meta_value, $attribute_key);
if (!is_wp_error($term) && is_object($term) && $term->name) {
$meta_value = $term->name;
}
// If we have a product, and its not a term, try to find its non-sanitized name
} elseif ($this->product) {
$product_attributes = $this->product->get_attributes();
if (isset($product_attributes[$attribute_key])) {
$meta_key = wc_attribute_label($product_attributes[$attribute_key]['name']);
}
}
if ($flat) {
$meta_list[] = wp_kses_post(wc_attribute_label($attribute_key) . ': ' . apply_filters('woocommerce_order_item_display_meta_value', $meta_value));
} else {
$meta_list[] = '
<dt class="variation-' . sanitize_html_class(sanitize_text_field($meta_key)) . '">' . wp_kses_post(wc_attribute_label($attribute_key)) . ':</dt>
<dd class="variation-' . sanitize_html_class(sanitize_text_field($meta_key)) . '">' . wp_kses_post(wpautop(apply_filters('woocommerce_order_item_display_meta_value', $meta_value))) . '</dd>
';
}
}
}
if (!sizeof($meta_list)) {
return '';
}
$output = $flat ? '' : '<dl class="variation">';
if ($flat) {
$output .= implode(", \n", $meta_list);
} else {
$output .= implode('', $meta_list);
}
if (!$flat) {
$output .= '</dl>';
}
if ($return) {
return $output;
} else {
echo $output;
}
}
return '';
}
开发者ID:chhavinav,项目名称:fr.ilovejuice,代码行数:66,代码来源:class-wc-order-item-meta.php
示例6: wc_attribute_label
/**
* Compatibility function for outputting a woocommerce attribute label
*
* @since 1.0
* @param string $label the label to display
* @return string the label to display
*/
public static function wc_attribute_label($label)
{
if (self::is_wc_version_gte_2_1()) {
return wc_attribute_label($label);
} else {
global $woocommerce;
return $woocommerce->attribute_label($label);
}
}
开发者ID:AndyA,项目名称:River,代码行数:16,代码来源:class-wc-swatches-compatibility.php
示例7: output_csv
/**
* Sort the data for CSV output first
*
* @param int $product_id
* @param array $headers
* @param array $body
* @param array $items
*/
public static function output_csv($product_id, $headers, $body, $items)
{
$headers['quantity'] = __('Quantity', 'wcvendors');
$new_body = array();
foreach ($body as $i => $order) {
// Remove comments
unset($body[$i]['comments']);
// Remove all numeric keys in each order (these are the meta values we are redoing into new lines)
foreach ($order as $key => $col) {
if (is_int($key)) {
unset($order[$key]);
}
}
// New order row
$new_row = $body[$i];
// Remove order to redo
unset($body[$i]);
$order = new WC_Order($i);
foreach ($items[$i]['items'] as $item) {
$product_id = !empty($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
$new_row_with_meta = $new_row;
// Add the qty row
$new_row_with_meta[] = $item['qty'];
$item_meta = $item['name'];
if ($metadata = $order->has_meta($item['product_id'])) {
foreach ($metadata as $meta) {
// Skip hidden core fields
if (in_array($meta['meta_key'], apply_filters('woocommerce_hidden_order_itemmeta', array('_qty', '_tax_class', '_product_id', '_variation_id', '_line_subtotal', '_line_subtotal_tax', '_line_total', '_line_tax', WC_Vendors::$pv_options->get_option('sold_by_label'))))) {
continue;
}
// Skip serialised meta
if (is_serialized($meta['meta_value'])) {
continue;
}
// Get attribute data
if (taxonomy_exists(wc_sanitize_taxonomy_name($meta['meta_key']))) {
$term = get_term_by('slug', $meta['meta_value'], wc_sanitize_taxonomy_name($meta['meta_key']));
$meta['meta_key'] = wc_attribute_label(wc_sanitize_taxonomy_name($meta['meta_key']));
$meta['meta_value'] = isset($term->name) ? $term->name : $meta['meta_value'];
} else {
$meta['meta_key'] = apply_filters('woocommerce_attribute_label', wc_attribute_label($meta['meta_key'], $_product), $meta['meta_key']);
}
$item_meta .= wp_kses_post(rawurldecode($meta['meta_key'])) . ':' . wp_kses_post(wpautop(make_clickable(rawurldecode($meta['meta_value']))));
}
}
$new_row_with_meta['product'] = $item_meta;
$new_body[] = $new_row_with_meta;
}
}
$headers = apply_filters('wcvendors_csv_headers', $headers, $product_id, $items);
$body = apply_filters('wcvendors_csv_body', $new_body, $product_id, $items);
WCV_Export_CSV::download($headers, $body, $product_id);
}
开发者ID:stodorovic,项目名称:wcvendors,代码行数:61,代码来源:class-export-csv.php
示例8: display
/**
* Display meta in a formatted list
*
* @access public
* @param bool $flat (default: false)
* @param bool $return (default: false)
* @param string $hideprefix (default: _)
* @return string
*/
public function display($flat = false, $return = false, $hideprefix = '_')
{
if (!empty($this->meta)) {
$meta_list = array();
foreach ($this->meta as $meta_key => $meta_values) {
if (empty($meta_values) || !empty($hideprefix) && substr($meta_key, 0, 1) == $hideprefix) {
continue;
}
foreach ($meta_values as $meta_value) {
// Skip serialised meta
if (is_serialized($meta_value)) {
continue;
}
// If this is a term slug, get the term's nice name
if (taxonomy_exists(esc_attr(str_replace('attribute_', '', $meta_key)))) {
$term = get_term_by('slug', $meta_value, esc_attr(str_replace('attribute_', '', $meta_key)));
if (!is_wp_error($term) && $term->name) {
$meta_value = $term->name;
}
}
if ($flat) {
$meta_list[] = esc_attr(wc_attribute_label(str_replace('attribute_', '', $meta_key)) . ': ' . apply_filters('woocommerce_order_item_display_meta_value', $meta_value));
} else {
$meta_list[] = '<dt>' . wp_kses_post(wc_attribute_label(str_replace('attribute_', '', $meta_key))) . ':</dt><dd>' . wp_kses_post(wpautop(apply_filters('woocommerce_order_item_display_meta_value', $meta_value))) . '</dd>';
}
}
}
if (!sizeof($meta_list)) {
return '';
}
$output = $flat ? '' : '<dl class="variation">';
if ($flat) {
$output .= implode(", \n", $meta_list);
} else {
$output .= implode('', $meta_list);
}
if (!$flat) {
$output .= '</dl>';
}
if ($return) {
return $output;
} else {
echo $output;
}
}
return '';
}
开发者ID:hoonio,项目名称:PhoneAfrika,代码行数:56,代码来源:class-wc-order-item-meta.php
示例9: get_cart_item_data
private function get_cart_item_data($cart_item)
{
$item_data = array();
// Variation data
if (!empty($cart_item['data']->variation_id) && is_array($cart_item['variation'])) {
foreach ($cart_item['variation'] as $name => $value) {
if ('' === $value) {
continue;
}
$taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($name)));
// If this is a term slug, get the term's nice name
if (taxonomy_exists($taxonomy)) {
$term = get_term_by('slug', $value, $taxonomy);
if (!is_wp_error($term) && $term && $term->name) {
$value = $term->name;
}
$label = wc_attribute_label($taxonomy);
// If this is a custom option slug, get the options name
} else {
$value = apply_filters('woocommerce_variation_option_name', $value);
$product_attributes = $cart_item['data']->get_attributes();
if (isset($product_attributes[str_replace('attribute_', '', $name)])) {
$label = wc_attribute_label($product_attributes[str_replace('attribute_', '', $name)]['name']);
} else {
$label = $name;
}
}
$item_data[] = array('key' => $label, 'value' => $value);
}
}
// Filter item data to allow 3rd parties to add more to the array
$item_data = apply_filters('woocommerce_get_item_data', $item_data, $cart_item);
// Format item data ready to display
foreach ($item_data as $key => $data) {
// Set hidden to true to not display meta on cart.
if (!empty($data['hidden'])) {
unset($item_data[$key]);
continue;
}
$item_data[$key]['key'] = !empty($data['key']) ? $data['key'] : $data['name'];
$item_data[$key]['display'] = !empty($data['display']) ? $data['display'] : $data['value'];
}
return $item_data;
}
开发者ID:lucasstark,项目名称:gravityforms-woocommerce-cart-capture,代码行数:44,代码来源:gravity-cart-capture.php
示例10: wb_get_item_data
/**
*
* @param type $cart_item
* @param type $flat
* @return string
*/
function wb_get_item_data($cart_item, $flat = false)
{
$item_data = array();
if (!empty($cart_item['data']->variation_id) && is_array($cart_item['variation'])) {
foreach ($cart_item['variation'] as $name => $value) {
if ('' === $value) {
continue;
}
$taxonomy = wc_attribute_taxonomy_name(str_replace('attribute_pa_', '', urldecode($name)));
if (taxonomy_exists($taxonomy)) {
$term = get_term_by('slug', $value, $taxonomy);
if (!is_wp_error($term) && $term && $term->name) {
$value = $term->name;
}
$label = wc_attribute_label($taxonomy);
} else {
$value = apply_filters('woocommerce_variation_option_name', $value);
$product_attributes = $cart_item['data']->get_attributes();
if (isset($product_attributes[str_replace('attribute_', '', $name)])) {
$label = wc_attribute_label($product_attributes[str_replace('attribute_', '', $name)]['name']);
} else {
$label = $name;
}
}
$item_data[] = array('key' => $label, 'value' => $value);
}
}
$other_data = apply_filters('woocommerce_get_item_data', array(), $cart_item);
if ($other_data && is_array($other_data) && sizeof($other_data) > 0) {
foreach ($other_data as $data) {
if (empty($data['hidden'])) {
$display_value = !empty($data['display']) ? $data['display'] : $data['value'];
$item_data[] = array('key' => $data['name'], 'value' => $display_value);
}
}
}
if (sizeof($item_data) > 0) {
return $item_data;
}
return '';
}
开发者ID:bear12345678,项目名称:keylessoption,代码行数:47,代码来源:wb-cart-functions.php
示例11: wcj_get_order_item_meta_info
/**
* wcj_get_order_item_meta_info.
*
* from woocommerce\includes\admin\meta-boxes\views\html-order-item-meta.php
*
* @version 2.5.9
* @since 2.5.9
*/
function wcj_get_order_item_meta_info($item_id, $item, $_order, $exclude_wcj_meta = false, $_product = null)
{
$meta_info = '';
if ($metadata = $_order->has_meta($item_id)) {
$meta_info = array();
foreach ($metadata as $meta) {
// Skip hidden core fields
if (in_array($meta['meta_key'], apply_filters('woocommerce_hidden_order_itemmeta', array('_qty', '_tax_class', '_product_id', '_variation_id', '_line_subtotal', '_line_subtotal_tax', '_line_total', '_line_tax', 'method_id', 'cost')))) {
continue;
}
if ($exclude_wcj_meta && ('wcj' === substr($meta['meta_key'], 0, 3) || '_wcj' === substr($meta['meta_key'], 0, 4))) {
continue;
}
// Skip serialised meta
if (is_serialized($meta['meta_value'])) {
continue;
}
// Get attribute data
if (taxonomy_exists(wc_sanitize_taxonomy_name($meta['meta_key']))) {
$term = get_term_by('slug', $meta['meta_value'], wc_sanitize_taxonomy_name($meta['meta_key']));
$meta['meta_key'] = wc_attribute_label(wc_sanitize_taxonomy_name($meta['meta_key']));
$meta['meta_value'] = isset($term->name) ? $term->name : $meta['meta_value'];
} else {
$the_product = null;
if (is_object($_product)) {
$the_product = $_product;
} elseif (is_object($item)) {
$the_product = $_order->get_product_from_item($item);
}
$meta['meta_key'] = is_object($the_product) ? wc_attribute_label($meta['meta_key'], $the_product) : $meta['meta_key'];
}
$meta_info[] = wp_kses_post(rawurldecode($meta['meta_key'])) . ': ' . wp_kses_post(rawurldecode($meta['meta_value']));
}
$meta_info = implode(', ', $meta_info);
}
return $meta_info;
}
开发者ID:algoritmika,项目名称:woocommerce-jetpack,代码行数:45,代码来源:wcj-functions.php
示例12: 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…', '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
示例13: wc_cp_validation
//.........这里部分代码省略.........
// Get value from post data.
if ($attribute['is_taxonomy']) {
$value = sanitize_title(stripslashes($_REQUEST['wccp_' . $taxonomy][$component_id]));
} else {
$value = wc_clean(stripslashes($_REQUEST['wccp_' . $taxonomy][$component_id]));
}
} 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 "%2$s" field', '%1$s are required "%2$s" 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 "%1$s" 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 "%1$s" configuration cannot be added to the cart. Please choose "%2$s" options…', '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;
}
开发者ID:alexbaron50,项目名称:Rockk3rs-Lab-Test,代码行数:67,代码来源:class-wc-cp-cart.php
示例14: get_products_atts
function get_products_atts()
{
$total_products = 0;
$products_attributes = array();
$attributes_names = array();
$attributes_names['wcj_title'] = __('Product', 'woocommerce-jetpack');
$attributes_names['wcj_category'] = __('Category', 'woocommerce-jetpack');
$offset = 0;
$block_size = 96;
while (true) {
$args_products = array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => $block_size, 'orderby' => 'title', 'order' => 'ASC', 'offset' => $offset);
$loop_products = new WP_Query($args_products);
if (!$loop_products->have_posts()) {
break;
}
while ($loop_products->have_posts()) {
$loop_products->the_post();
$total_products++;
$product_id = $loop_products->post->ID;
$the_product = wc_get_product($product_id);
$products_attributes[$product_id]['wcj_title'] = '<a href="' . get_permalink($product_id) . '">' . $the_product->get_title() . '</a>';
$products_attributes[$product_id]['wcj_category'] = $the_product->get_categories();
foreach ($the_product->get_attributes() as $attribute) {
$products_attributes[$product_id][$attribute['name']] = $the_product->get_attribute($attribute['name']);
if (!isset($attributes_names[$attribute['name']])) {
$attributes_names[$attribute['name']] = wc_attribute_label($attribute['name']);
}
}
}
$offset += $block_size;
}
$table_data = array();
if (isset($_GET['wcj_attribute']) && '' != $_GET['wcj_attribute']) {
$table_data[] = array(__('Product', 'woocommerce-jetpack'), __('Category', 'woocommerce-jetpack'), $_GET['wcj_attribute']);
} else {
// $table_data[] = array_values( $attributes_names );
$table_data[] = array_keys($attributes_names);
}
foreach ($attributes_names as $attributes_name => $attribute_title) {
if (isset($_GET['wcj_attribute']) && '' != $_GET['wcj_attribute']) {
if ('wcj_title' != $attributes_name && 'wcj_category' != $attributes_name && $_GET['wcj_attribute'] != $attributes_name) {
continue;
}
}
foreach ($products_attributes as $product_id => $product_attributes) {
$table_data[$product_id][$attributes_name] = isset($product_attributes[$attributes_name]) ? $product_attributes[$attributes_name] : '';
}
}
return '<p>' . __('Total Products:', 'woocommerce-jetpack') . ' ' . $total_products . '</p>' . wcj_get_table_html($table_data, array('table_class' => 'widefat striped'));
}
开发者ID:algoritmika,项目名称:woocommerce-jetpack,代码行数:50,代码来源:class-wcj-general.php
示例15: get_attributes
/**
* Get the attributes for a product or product variation
*
* @since 2.1
* @param WC_Product|WC_Product_Variation $product
* @return array
*/
private function get_attributes($product)
{
$attributes = array();
if ($product->is_type('variation')) {
// variation attributes
foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
// taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
$attributes[] = array('name' => wc_attribute_label(str_replace('attribute_', '', $attribute_name)), 'slug' => str_replace('attribute_', '', str_replace('pa_', '', $attribute_name)), 'option' => $attribute);
}
} else {
foreach ($product->get_attributes() as $attribute) {
// taxonomy-based attributes are comma-separated, others are pipe (|) separated
if ($attribute['is_taxonomy']) {
$options = explode(',', $product->get_attribute($attribute['name']));
} else {
$options = explode('|', $product->get_attribute($attribute['name']));
}
$attributes[] = array('name' => wc_attribute_label($attribute['name']), 'slug' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => array_map('trim', $options));
}
}
return $attributes;
}
开发者ID:haltaction,项目名称:woocommerce,代码行数:29,代码来源:class-wc-api-products.php
示例16: foreach
?>
</div>
</li>
<?php
}
}
foreach ($product->get_attributes() as $attribute) {
if (empty($attribute['is_visible']) || $attribute['is_taxonomy'] && !taxonomy_exists($attribute['name'])) {
continue;
} else {
$show = true;
}
?>
<li class="clearfix">
<div class="halfcol left"><?php
echo wc_attribute_label($attribute['name']);
?>
</div>
<div class="halfcol right">
<?php
if ($attribute['is_taxonomy']) {
$values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
echo apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
} else {
$values = array_map('trim', explode(WC_DELIMITER, $attribute['value']));
echo apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
}
?>
</div>
</li>
<?php
开发者ID:TheTypoMaster,项目名称:wp_marketplace,代码行数:31,代码来源:content-single-product.php
示例17: output_variations
//.........这里部分代码省略.........
// Get variations
$args = array('post_type' => 'product_variation', 'post_status' => array('private', 'publish'), 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID);
$variations = get_posts($args);
$loop = 0;
if ($variations) {
foreach ($variations as $variation) {
$variation_id = absint($variation->ID);
$variation_meta = get_post_meta($variation_id);
$variation_data = array();
$shipping_classes = get_the_terms($variation_id, 'product_shipping_class');
$variation_fields = array('_sku' => '', '_stock' => '', '_regular_price' => '', '_sale_price' => '', '_weight' => '', '_length' => '', '_width' => '', '_height' => '', '_download_limit' => '', '_download_expiry' => '', '_downloadable_files' => '', '_downloadable' => '', '_virtual' => '', '_thumbnail_id' => '', '_sale_price_dates_from' => '', '_sale_price_dates_to' => '', '_manage_stock' => '', '_stock_status' => '', '_backorders' => null, '_tax_class' => null);
foreach ($variation_fields as $field => $value) {
$variation_data[$field] = isset($variation_meta[$field][0]) ? maybe_unserialize($variation_meta[$field][0]) : $value;
}
// Add the variation attributes
foreach ($variation_meta as $key => $value) {
if (false !== strpos($key, 'attribute_')) {
$variation_data[$key] = $value;
}
}
// Formatting
$variation_data['_regular_price'] = wc_format_localized_price($variation_data['_regular_price']);
$variation_data['_sale_price'] = wc_format_localized_price($variation_data['_sale_price']);
$variation_data['_weight'] = wc_format_localized_decimal($variation_data['_weight']);
$variation_data['_length'] = wc_format_localized_decimal($variation_data['_length']);
$variation_data['_width'] = wc_format_localized_decimal($variation_data['_width']);
$variation_data['_height'] = wc_format_localized_decimal($variation_data['_height']);
$variation_data['_thumbnail_id'] = absint($variation_data['_thumbnail_id']);
$variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url($variation_data['_thumbnail_id']) : '';
$variation_data['shipping_class'] = $shipping_classes && !is_wp_error($shipping_classes) ? current($shipping_classes)->term_id : '';
// Stock BW compat
if ('' !== $variation_data['_stock']) {
$variation_data['_manage_stock'] = 'y
|
请发表评论