当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Product_Variation::set_regular_price方法代码示例

本文整理汇总了PHP中WC_Product_Variation::set_regular_price方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variation::set_regular_price方法的具体用法?PHP WC_Product_Variation::set_regular_price怎么用?PHP WC_Product_Variation::set_regular_price使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Product_Variation的用法示例。


在下文中一共展示了WC_Product_Variation::set_regular_price方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:76,代码来源:data-store.php


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