本文整理汇总了PHP中WC_Product::get_variation_attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::get_variation_attributes方法的具体用法?PHP WC_Product::get_variation_attributes怎么用?PHP WC_Product::get_variation_attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::get_variation_attributes方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format_wc_variation_for_square_api
/**
* Convert a WC Product or Variation into a Square ItemVariation
* See: https://docs.connect.squareup.com/api/connect/v1/#datatype-itemvariation
*
* @param WC_Product|WC_Product_Variation $variation
* @param bool $include_inventory
* @return array Formatted as a Square ItemVariation
*/
public static function format_wc_variation_for_square_api($variation, $include_inventory = false)
{
$formatted = array('name' => null, 'pricing_type' => null, 'price_money' => null, 'sku' => null, 'track_inventory' => null, 'inventory_alert_type' => null, 'inventory_alert_threshold' => null, 'user_data' => null);
if ($variation instanceof WC_Product) {
$formatted['name'] = __('Regular', 'woocommerce-square');
$formatted['price_money'] = array('currency_code' => apply_filters('woocommerce_square_currency', get_woocommerce_currency()), 'amount' => $variation->get_display_price() * 100);
$formatted['sku'] = $variation->get_sku();
if ($include_inventory && $variation->managing_stock()) {
$formatted['track_inventory'] = true;
}
}
if ($variation instanceof WC_Product_Variation) {
$formatted['name'] = implode(', ', $variation->get_variation_attributes());
}
return array_filter($formatted);
}
示例2: 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;
}
示例3: add_product
/**
* Add a product line item to the order. This is the only line item type with
* it's own method because it saves looking up order amounts (costs are added up for you).
* @param \WC_Product $product
* @param int $qty
* @param array $args
* @return int order item ID
* @throws WC_Data_Exception
*/
public function add_product($product, $qty = 1, $args = array())
{
if ($product) {
$default_args = array('name' => $product->get_title(), 'tax_class' => $product->get_tax_class(), 'product_id' => $product->get_id(), 'variation_id' => isset($product->variation_id) ? $product->variation_id : 0, 'variation' => isset($product->variation_id) ? $product->get_variation_attributes() : array(), 'subtotal' => $product->get_price_excluding_tax($qty), 'total' => $product->get_price_excluding_tax($qty), 'quantity' => $qty);
} else {
$default_args = array('quantity' => $qty);
}
$args = wp_parse_args($args, $default_args);
// BW compatibility with old args
if (isset($args['totals'])) {
foreach ($args['totals'] as $key => $value) {
if ('tax' === $key) {
$args['total_tax'] = $value;
} elseif ('tax_data' === $key) {
$args['taxes'] = $value;
} else {
$args[$key] = $value;
}
}
}
$item = new WC_Order_Item_Product($args);
$item->set_backorder_meta();
$item->set_order_id($this->get_id());
$item->save();
$this->add_item($item);
wc_do_deprecated_action('woocommerce_order_add_product', array($this->get_id(), $item->get_id(), $product, $qty, $args), '2.7', 'Use woocommerce_new_order_item action instead.');
return $item->get_id();
}
示例4: render_product_tab_content
public function render_product_tab_content()
{
global $woocommerce, $post;
global $_wp_additional_image_sizes;
add_filter('woocommerce_variation_is_visible', array($this, 'return_true'));
$post_id = $post->ID;
if (function_exists('get_product')) {
$product = get_product($post->ID);
} else {
$product = new WC_Product($post->ID);
}
$product_type_array = array('variable', 'variable-subscription');
if (!in_array($product->product_type, $product_type_array)) {
return;
}
$swatch_type_options = get_post_meta($post_id, '_swatch_type_options', true);
$swatch_type = get_post_meta($post_id, '_swatch_type', true);
$swatch_size = get_post_meta($post_id, '_swatch_size', true);
if (!$swatch_type_options) {
$swatch_type_options = array();
}
if (!$swatch_type) {
$swatch_type = 'standard';
}
if (!$swatch_size) {
$swatch_size = 'swatches_image_size';
}
echo '<div class="options_group">';
?>
<div class="fields_header">
<table class="wcsap widefat">
<thead>
<th class="attribute_swatch_label">
<?php
_e('Product Attribute Name', 'wc_swatches_and_photos');
?>
</th>
<th class="attribute_swatch_type">
<?php
_e('Attribute Control Type', 'wc_swatches_and_photos');
?>
</th>
</thead>
</table>
</div>
<div class="fields">
<?php
$woocommerce_taxonomies = WC_Swatches_Compatibility::wc_get_attribute_taxonomies();
$woocommerce_taxonomy_infos = array();
foreach ($woocommerce_taxonomies as $tax) {
$woocommerce_taxonomy_infos[WC_Swatches_Compatibility::wc_attribute_taxonomy_name($tax->attribute_name)] = $tax;
}
$tax = null;
$attributes = $product->get_variation_attributes();
//Attributes configured on this product already.
if ($attributes && count($attributes)) {
$attribute_names = array_keys($attributes);
foreach ($attribute_names as $name) {
$key = md5(sanitize_title($name));
$old_key = sanitize_title($name);
$key_attr = md5(str_replace('-', '_', sanitize_title($name)));
$current_is_taxonomy = taxonomy_exists($name);
$current_type = 'default';
$current_type_description = 'None';
$current_size = 'swatches_image_size';
$current_layout = 'default';
$current_size_height = '32';
$current_size_width = '32';
$current_label = 'Unknown';
$current_options = false;
if (isset($swatch_type_options[$key])) {
$current_options = $swatch_type_options[$key];
} elseif (isset($swatch_type_options[$old_key])) {
$current_options = $swatch_type_options[$old_key];
}
if ($current_options) {
$current_size = $current_options['size'];
$current_type = $current_options['type'];
$current_layout = isset($current_options['layout']) ? $current_options['layout'] : 'default';
if ($current_type != 'default') {
$current_type_description = $current_type == 'term_options' ? __('Taxonomy Colors and Images', 'wc_swatches_and_photos') : __('Custom Product Colors and Images', 'wc_swatches_and_photos');
}
}
$the_size = isset($_wp_additional_image_sizes[$current_size]) ? $_wp_additional_image_sizes[$current_size] : $_wp_additional_image_sizes['swatches_image_size'];
if (isset($the_size['width']) && isset($the_size['height'])) {
$current_size_width = $the_size['width'];
$current_size_height = $the_size['height'];
} else {
$current_size_width = 32;
$current_size_height = 32;
}
$attribute_terms = array();
if (taxonomy_exists($name)) {
$tax = get_taxonomy($name);
$woocommerce_taxonomy = $woocommerce_taxonomy_infos[$name];
$current_label = isset($woocommerce_taxonomy->attribute_label) && !empty($woocommerce_taxonomy->attribute_label) ? $woocommerce_taxonomy->attribute_label : $woocommerce_taxonomy->attribute_name;
$terms = get_terms($name, array('hide_empty' => false));
$selected_terms = isset($attributes[$name]) ? $attributes[$name] : array();
//.........这里部分代码省略.........
示例5: 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' => ucwords(str_replace('attribute_', '', str_replace('pa_', '', $attribute_name))), 'option' => $attribute);
}
} else {
foreach ($product->get_attributes() as $attribute) {
$attributes[] = array('name' => ucwords(str_replace('pa_', '', $attribute['name'])), 'position' => $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->get_id(), $attribute));
}
}
return $attributes;
}
示例6: save_default_attributes
/**
* Save default attributes.
*
* @since 2.7.0
*
* @param WC_Product $product Product instance.
* @param WP_REST_Request $request Request data.
* @return WC_Product
*/
protected function save_default_attributes($product, $request)
{
if (isset($request['default_attributes']) && is_array($request['default_attributes'])) {
$attributes = $product->get_variation_attributes();
$default_attributes = array();
foreach ($request['default_attributes'] as $attribute) {
$attribute_id = 0;
$attribute_name = '';
// Check ID for global attributes or name for product attributes.
if (!empty($attribute['id'])) {
$attribute_id = absint($attribute['id']);
$attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
} elseif (!empty($attribute['name'])) {
$attribute_name = sanitize_title($attribute['name']);
}
if (!$attribute_id && !$attribute_name) {
continue;
}
if (isset($attributes[$attribute_name])) {
$_attribute = $attributes[$attribute_name];
if ($_attribute['is_variation']) {
$value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
if (!empty($_attribute['is_taxonomy'])) {
// If dealing with a taxonomy, we need to get the slug from the name posted to the API.
$term = get_term_by('name', $value, $attribute_name);
if ($term && !is_wp_error($term)) {
$value = $term->slug;
} else {
$value = sanitize_title($value);
}
}
if ($value) {
$default_attributes[$attribute_name] = $value;
}
}
}
}
$product->set_default_attributes($default_attributes);
}
return $product;
}
示例7: get_attributes
/**
* Get the attributes for a product or product variation.
*
* @param WC_Product|WC_Product_Variation $product
* @return array
*/
protected function get_attributes($product)
{
$attributes = array();
if ($product->is_type('variation')) {
// Variation attributes.
foreach ($product->get_variation_attributes() as $attribute_name => $attribute) {
$name = str_replace('attribute_', '', $attribute_name);
// Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`.
if (0 === strpos($attribute_name, 'attribute_pa_')) {
$attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($name), 'name' => $this->get_attribute_taxonomy_label($name), 'option' => $attribute);
} else {
$attributes[] = array('id' => 0, 'name' => str_replace('pa_', '', $name), 'option' => $attribute);
}
}
} else {
foreach ($product->get_attributes() as $attribute) {
if ($attribute['is_taxonomy']) {
$attributes[] = array('id' => wc_attribute_taxonomy_id_by_name($attribute['name']), 'name' => $this->get_attribute_taxonomy_label($attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->id, $attribute));
} else {
$attributes[] = array('id' => 0, 'name' => str_replace('pa_', '', $attribute['name']), 'position' => (int) $attribute['position'], 'visible' => (bool) $attribute['is_visible'], 'variation' => (bool) $attribute['is_variation'], 'options' => $this->get_attribute_options($product->id, $attribute));
}
}
}
return $attributes;
}
示例8: foreach
//.........这里部分代码省略.........
if (!$description_value) {
$description_value = $value[0];
}
$description .= $description_name . ': ' . apply_filters('woocommerce_variation_option_name', $description_value) . ', ';
}
if (is_array($allowed_variations[$item_id]) && in_array($variation, $allowed_variations[$item_id])) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
echo '<option value="' . $variation . '" ' . $selected . '>#' . $variation . ' - ' . rtrim($description, ', ') . '</option>';
}
?>
</select>
<?php
woocommerce_wp_checkbox(array('id' => 'hide_filtered_variations_' . $item_id, 'wrapper_class' => 'hide_filtered_variations', 'label' => __('Hide Filtered-Out Options', 'woo-bundles'), 'description' => '<img class="help_tip" data-tip="' . __('Check to remove any filtered-out variation options from this item\'s drop-downs. If you leave the box unchecked, the options corresponding to filtered-out variations will be disabled but still visible.', 'woo-bundles') . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" />'));
?>
</div>
<div class="defaults">
<?php
woocommerce_wp_checkbox(array('id' => 'override_defaults_' . $item_id, 'wrapper_class' => 'override_defaults', 'label' => __('Override Default Selections', 'woo-bundles'), 'description' => '<img class="help_tip" data-tip="' . __('In effect for this bundle only. The available options are in sync with the filtering settings above. Always save any changes made above before configuring this section.', 'woo-bundles') . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" />'));
?>
</div>
<div class="bundle_selection_defaults indented"> <?php
// get normal variation attributes
$attributes = $bundled_product->get_variation_attributes();
// filtered variation attributes
$filtered_attributes = array();
// get filter-active setting
$filtered = get_post_meta($post->ID, 'filter_variations_' . $item_id, true) == 'yes' ? true : false;
// if filter is active, show only the attributes of the selected variations
if ($filtered) {
foreach ($allowed_variations[$item_id] as $allowed_variation_id) {
// get variation meta of allowed variations
$product_custom_fields = get_post_custom($allowed_variation_id);
foreach ($product_custom_fields as $name => $value) {
if (!strstr($name, 'attribute_')) {
continue;
}
$attribute_name = substr($name, strlen('attribute_'));
if (!isset($filtered_attributes[$attribute_name])) {
$filtered_attributes[$attribute_name][] = $value[0];
} elseif (!in_array($value[0], $filtered_attributes[$attribute_name])) {
$filtered_attributes[$attribute_name][] = $value[0];
}
}
}
}
foreach ($attributes as $name => $values) {
sort($values);
// Get current value for variation (if set)
$variation_selected_value = isset($default_attributes[$item_id][sanitize_title($name)]) ? $default_attributes[$item_id][sanitize_title($name)] : '';
// Name will be something like attribute_pa_color
echo '<select name="default_attributes[' . $item_id . '][' . sanitize_title($name) . ']"><option value="">' . __('No default', 'woocommerce') . ' ' . $woocommerce->attribute_label($name) . '…</option>';
foreach ($values as $value) {
// if filters exist, only show the entries available in the filtered_attributes array
if ($filtered && isset($filtered_attributes[sanitize_title($name)])) {
if (!in_array($value, $filtered_attributes[sanitize_title($name)]) && !in_array('', $filtered_attributes[sanitize_title($name)])) {
示例9: array
function load_bundle_data()
{
global $woocommerce_bundles;
// stores bundle pricing strategy info and price table
$this->bundle_price_data = array();
$this->bundle_price_data['currency_symbol'] = get_woocommerce_currency_symbol();
$this->bundle_price_data['woocommerce_price_num_decimals'] = (int) get_option('woocommerce_price_num_decimals');
$this->bundle_price_data['woocommerce_currency_pos'] = get_option('woocommerce_currency_pos');
$this->bundle_price_data['woocommerce_price_decimal_sep'] = stripslashes(get_option('woocommerce_price_decimal_sep'));
$this->bundle_price_data['woocommerce_price_thousand_sep'] = stripslashes(get_option('woocommerce_price_thousand_sep'));
$this->bundle_price_data['woocommerce_price_trim_zeros'] = get_option('woocommerce_price_trim_zeros');
$this->bundle_price_data['free'] = __('Free!', 'woocommerce');
$this->bundle_price_data['per_product_pricing'] = $this->per_product_pricing_active;
$this->bundle_price_data['prices'] = array();
$this->bundle_price_data['regular_prices'] = array();
$this->bundle_price_data['total'] = $this->per_product_pricing_active ? (double) 0 : (double) ($this->get_price() == '' ? -1 : $this->get_price());
$this->bundle_price_data['regular_total'] = $this->per_product_pricing_active ? (double) 0 : (double) $this->regular_price;
$this->bundle_price_data['total_description'] = __('Total', 'woo-bundles') . ': ';
$this->bundle_attributes = array();
$this->available_bundle_variations = array();
$this->selected_bundle_attributes = array();
$this->bundled_products = array();
foreach ($this->bundled_item_ids as $bundled_item_id) {
// remove suffix
$sep = explode('_', $bundled_item_id);
$product_id = $sep[0];
$bundled_product_post = get_post($product_id);
if (get_post_status($product_id) != 'publish') {
continue;
}
if ($this->is_wc_v2) {
$bundled_product = get_product($product_id);
} else {
$bundled_product = new WC_Product($product_id);
}
$this->bundled_products[$bundled_item_id] = $bundled_product;
if ($bundled_product->product_type == 'simple') {
if (!$bundled_product->is_sold_individually()) {
$this->sold_individually = false;
}
// price for simple products gets stored now, for variable products jquery gets the job done
$this->bundle_price_data['prices'][$bundled_product->id] = (double) $bundled_product->get_price();
$this->bundle_price_data['regular_prices'][$bundled_product->id] = (double) $bundled_product->regular_price;
// no variation data to load - product is simple
$this->min_bundle_price = $this->min_bundle_price + $this->bundled_item_quantities[$bundled_item_id] * $bundled_product->get_price();
$this->min_bundle_regular_price = $this->min_bundle_regular_price + $this->bundled_item_quantities[$bundled_item_id] * $bundled_product->regular_price;
$this->max_bundle_price = $this->max_bundle_price + $this->bundled_item_quantities[$bundled_item_id] * $bundled_product->get_price();
$this->max_bundle_regular_price = $this->max_bundle_regular_price + $this->bundled_item_quantities[$bundled_item_id] * $bundled_product->regular_price;
} elseif ($bundled_product->product_type == 'variable') {
// prepare price variable for jquery
$this->bundle_price_data['prices'][$bundled_item_id] = 0;
$this->bundle_price_data['regular_prices'][$bundled_item_id] = 0;
// get all available attributes and settings
$this->bundle_attributes[$bundled_item_id] = $bundled_product->get_variation_attributes();
$default_product_attributes = array();
if ($this->bundle_defaults_active[$bundled_item_id]) {
$default_product_attributes = $this->bundle_defaults[$bundled_item_id];
} else {
$default_product_attributes = (array) maybe_unserialize(get_post_meta($bundled_product_post->ID, '_default_attributes', true));
}
$this->selected_bundle_attributes[$bundled_item_id] = apply_filters('woocommerce_product_default_attributes', $default_product_attributes);
// calculate min-max variation prices
$min_variation_regular_price = '';
$min_variation_sale_price = '';
$max_variation_regular_price = '';
$max_variation_sale_price = '';
foreach ($bundled_product->get_children() as $child_id) {
$variation = $bundled_product->get_child($child_id);
// stop here if this variation is not within the active set (prices will not include this variation)
if ($this->variation_filters_active[$bundled_item_id]) {
if (!is_array($this->allowed_variations[$bundled_item_id])) {
continue;
}
if (!in_array($child_id, $this->allowed_variations[$bundled_item_id])) {
continue;
}
}
if ($variation instanceof WC_Product_Variation) {
if (get_post_status($variation->get_variation_id()) != 'publish') {
continue;
}
// Disabled
if (!$variation->is_sold_individually()) {
$this->sold_individually = false;
}
// variation min-max price calculation
$variation_price = get_post_meta($child_id, '_price', true);
$variation_sale_price = get_post_meta($child_id, '_sale_price', true);
// Low price
if (!is_numeric($min_variation_regular_price) || $variation_price < $min_variation_regular_price) {
$min_variation_regular_price = $variation_price;
}
if ($variation_sale_price !== '' && (!is_numeric($min_variation_sale_price) || $variation_sale_price < $min_variation_sale_price)) {
$min_variation_sale_price = $variation_sale_price;
}
// High price
if (!is_numeric($max_variation_regular_price) || $variation_price > $max_variation_regular_price) {
$max_variation_regular_price = $variation_price;
}
if ($variation_sale_price !== '' && (!is_numeric($max_variation_sale_price) || $variation_sale_price > $max_variation_sale_price)) {
//.........这里部分代码省略.........
示例10: woocommerce_bulk_variations_create_matrix_v24
/** Modified Function - create matrix for row -- 03/02/2016 **/
function woocommerce_bulk_variations_create_matrix_v24($post_id)
{
// 2.0 Compat
if (function_exists('get_product')) {
$_product = get_product($post_id);
} else {
$_product = new WC_Product($post_id);
}
$attributes = $_product->get_attributes();
//Get first attribute -- 03/02/2016
if (is_array($attributes) && count($attributes) > 0) {
foreach ($attributes as $att) {
$row_attribute = $att['name'];
break;
}
}
$av_temp = $_product->get_variation_attributes();
$av = array();
if (isset($attributes[$row_attribute]) && $attributes[$row_attribute]['is_taxonomy']) {
$row_term_values = WC_Bulk_Variations_Compatibility::wc_get_product_terms($post_id, $row_attribute, 'all');
foreach ($row_term_values as $row_term_value) {
if (in_array($row_term_value->slug, $av_temp[$row_attribute])) {
$av[$row_attribute][] = $row_term_value->slug;
}
}
} else {
$av[$row_attribute] = $av_temp[$row_attribute];
}
$grid = array();
foreach ($av[$row_attribute] as $row_value) {
$grid[$row_value] = null;
}
//Now sanitize the attributes, since $product->get_available_variations returns the variations sanitized, but get_variation_attributes does not
$row_attribute = sanitize_title($row_attribute);
$pv = $_product->get_available_variations();
$filter = new WC_Bulk_Variation_Array_Filter('attribute_' . $row_attribute, $pv);
foreach ($grid as $row_key => &$field_value) {
$field_value = $filter->get_matches($row_key);
}
$matrix_data = array('row_attribute' => $row_attribute, 'matrix_rows' => array_values($av[$row_attribute]), 'matrix' => $grid);
return $matrix_data;
}
开发者ID:jmagallanes,项目名称:cultura-woo-bulk-variations,代码行数:43,代码来源:woocommerce-bulk-variations-functions.php
示例11: woogle_build_product
//.........这里部分代码省略.........
// Shipping dimensions
$wc_dimension_unit = get_option('woocommerce_dimension_unit', 'cm');
$wc_product_length = $wc_product->get_length();
if (!empty($wc_product_length)) {
$dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
$dimension->setValue($wc_product_length);
$dimension->setUnit($wc_dimension_unit);
$product->setShippingLength($dimension);
}
$wc_product_width = $wc_product->get_width();
if (!empty($wc_product_width)) {
$dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
$dimension->setValue($wc_product_width);
$dimension->setUnit($wc_dimension_unit);
$product->setShippingWidth($dimension);
}
$wc_product_height = $wc_product->get_height();
if (!empty($wc_product_height)) {
$dimension = new Google_Service_ShoppingContent_ProductShippingDimension();
$dimension->setValue($wc_product_height);
$dimension->setUnit($wc_dimension_unit);
$product->setShippingHeight($dimension);
}
// Attributes
$color = null;
$material = null;
$pattern = null;
$size = null;
$age_group = null;
$gender = null;
$adult = null;
if ($wc_product->is_type('variation')) {
// Variable product
$wc_variation_attributes = $wc_product->get_variation_attributes();
foreach ($wc_variation_attributes as $name => $value) {
if (!empty($value)) {
$attribute = new Google_Service_ShoppingContent_ProductCustomAttribute();
$attribute->setName($name);
$attribute->setValue($value);
$attribute->setType('text');
$product_custom_attributes[] = $attribute;
// Google attributes
if (empty($color)) {
$color = woogle_maybe_get_attribute('color', $name, $value);
}
if (empty($material)) {
$material = woogle_maybe_get_attribute('material', $name, $value);
}
if (empty($pattern)) {
$pattern = woogle_maybe_get_attribute('pattern', $name, $value);
}
if (empty($size)) {
$size = woogle_maybe_get_attribute('size', $name, $value);
}
if (empty($age_group)) {
$age_group = woogle_maybe_get_attribute('age-group', $name, $value);
}
if (empty($gender)) {
$gender = woogle_maybe_get_attribute('gender', $name, $value);
}
if (empty($adult)) {
$adult = woogle_maybe_get_attribute('adult', $name, $value);
}
}
}
} else {