本文整理汇总了PHP中WC_Product_Variable::get_variation_attributes方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variable::get_variation_attributes方法的具体用法?PHP WC_Product_Variable::get_variation_attributes怎么用?PHP WC_Product_Variable::get_variation_attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product_Variable
的用法示例。
在下文中一共展示了WC_Product_Variable::get_variation_attributes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* Test variable and variations.
*
* @since 2.7.0
*/
function test_variables_and_variations()
{
$product = new WC_Product_Variable();
$product->set_name('Variable Product');
$attribute = new WC_Product_Attribute();
$attribute->set_id(0);
$attribute->set_name('pa_color');
$attribute->set_options(explode(WC_DELIMITER, 'green | red'));
$attribute->set_visible(false);
$attribute->set_variation(true);
$product->set_attributes(array($attribute));
$product->save();
$this->assertEquals('Variable Product', $product->get_name());
$variation = new WC_Product_Variation();
$variation->set_name('Variation #1 of Dummy Variable CRUD Product');
$variation->set_parent_id($product->get_id());
$variation->set_regular_price(10);
$variation->set_sku('CRUD DUMMY SKU VARIABLE GREEN');
$variation->set_manage_stock('no');
$variation->set_downloadable('no');
$variation->set_virtual('no');
$variation->set_stock_status('instock');
$variation->set_attributes(array('pa_color' => 'green'));
$variation->save();
$this->assertEquals('Variation #1 of Dummy Variable CRUD Product', $variation->get_name());
$this->assertEquals('CRUD DUMMY SKU VARIABLE GREEN', $variation->get_sku());
$this->assertEquals(10, $variation->get_price());
$product = new WC_Product_Variable($product->get_id());
$children = $product->get_children();
$this->assertEquals($variation->get_id(), $children[0]);
$expected_attributes = array('pa_color' => array('green'));
$this->assertEquals($expected_attributes, $product->get_variation_attributes());
$variation_2 = new WC_Product_Variation();
$variation_2->set_name('Variation #2 of Dummy Variable CRUD Product');
$variation_2->set_parent_id($product->get_id());
$variation_2->set_regular_price(10);
$variation_2->set_sku('CRUD DUMMY SKU VARIABLE RED');
$variation_2->set_manage_stock('no');
$variation_2->set_downloadable('no');
$variation_2->set_virtual('no');
$variation_2->set_stock_status('instock');
$variation_2->set_attributes(array('pa_color' => 'red'));
$variation_2->save();
$this->assertEquals('Variation #2 of Dummy Variable CRUD Product', $variation_2->get_name());
$this->assertEquals('CRUD DUMMY SKU VARIABLE RED', $variation_2->get_sku());
$this->assertEquals(10, $variation_2->get_price());
$product = new WC_Product_Variable($product->get_id());
$children = $product->get_children();
$this->assertEquals($variation_2->get_id(), $children[1]);
$this->assertEquals(2, count($children));
$expected_attributes = array('pa_color' => array('green', 'red'));
$this->assertEquals($expected_attributes, $product->get_variation_attributes());
$variation_2->set_name('UPDATED - Variation #2 of Dummy Variable CRUD Product');
$variation_2->set_regular_price(15);
$variation_2->set_sale_price(9.99);
$variation_2->set_date_on_sale_to('32532537600');
$variation_2->save();
$product = new WC_Product_Variable($product->get_id());
$expected_prices['price'][$children[0]] = 10.0;
$expected_prices['price'][$children[1]] = 9.99;
$expected_prices['regular_price'][$children[0]] = 10.0;
$expected_prices['regular_price'][$children[1]] = 15.0;
$expected_prices['sale_price'][$children[0]] = 10.0;
$expected_prices['sale_price'][$children[1]] = 9.99;
$this->assertEquals($expected_prices, $product->get_variation_prices());
$this->assertEquals('UPDATED - Variation #2 of Dummy Variable CRUD Product', $variation_2->get_name());
$product->set_name('Renamed Variable Product');
$product->save();
$this->assertEquals('Renamed Variable Product', $product->get_name());
$product->delete();
}
示例2: wcva_return_displaytype_number
function wcva_return_displaytype_number($product, $post)
{
$displaytypenumber = 0;
$product = get_product($post->ID);
$_coloredvariables = get_post_meta($product->id, '_coloredvariables', true);
$displaytype = "none";
if ($product->product_type == 'variable') {
$product = new WC_Product_Variable($post->ID);
$attributes = $product->get_variation_attributes();
}
if (!empty($attributes) && sizeof($attributes) > 0) {
foreach ($attributes as $key => $values) {
if (isset($_coloredvariables[$key]['display_type'])) {
$displaytype = $_coloredvariables[$key]['display_type'];
}
if ($displaytype == "colororimage" || $displaytype == "radio") {
$displaytypenumber++;
}
}
}
return $displaytypenumber;
}
示例3: __
<div id="colored_variable_tab_data" class="panel woocommerce_options_panel">
<?php
$product = get_product($post->ID);
?>
<?php
if ($product->product_type == 'variable') {
?>
<?php
$product = new WC_Product_Variable($post->ID);
?>
<?php
$attributes = $product->get_variation_attributes();
?>
<?php
}
?>
<div class="wcva-upper-div">
<table class="widefat" width="100%" style="border:none;">
<tr>
<td width="70%"><?php
echo __('Enable one attribute swatches On shop/archive pages', 'wcva');
?>
</td>
<td width="30%"><input type="checkbox" id="wcva_shop_swatches" name="shop_swatches" value="yes" <?php
if (isset($shop_swatches) && $shop_swatches == "yes") {