本文整理汇总了PHP中WC_Product::set_width方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::set_width方法的具体用法?PHP WC_Product::set_width怎么用?PHP WC_Product::set_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::set_width方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_product_shipping_data
/**
* Save product shipping data
*
* @since 2.2
* @param WC_Product $product
* @param array $data
* @return WC_Product
*/
private function save_product_shipping_data($product, $data)
{
if (isset($data['weight'])) {
$product->set_weight('' === $data['weight'] ? '' : wc_format_decimal($data['weight']));
}
// Product dimensions
if (isset($data['dimensions'])) {
// Height
if (isset($data['dimensions']['height'])) {
$product->set_height('' === $data['dimensions']['height'] ? '' : wc_format_decimal($data['dimensions']['height']));
}
// Width
if (isset($data['dimensions']['width'])) {
$product->set_width('' === $data['dimensions']['width'] ? '' : wc_format_decimal($data['dimensions']['width']));
}
// Length
if (isset($data['dimensions']['length'])) {
$product->set_length('' === $data['dimensions']['length'] ? '' : wc_format_decimal($data['dimensions']['length']));
}
}
// Virtual
if (isset($data['virtual'])) {
$virtual = true === $data['virtual'] ? 'yes' : 'no';
if ('yes' == $virtual) {
$product->set_weight('');
$product->set_height('');
$product->set_length('');
$product->set_width('');
}
}
// Shipping class
if (isset($data['shipping_class'])) {
$data_store = $product->get_data_store();
$shipping_class_id = $data_store->get_shipping_class_id_by_slug(wc_clean($data['shipping_class']));
if ($shipping_class_id) {
$product->set_shipping_class_id($shipping_class_id);
}
}
return $product;
}
示例2: save_product_shipping_data
/**
* Save product shipping data.
*
* @param WC_Product $product Product instance.
* @param array $data Shipping data.
* @return WC_Product
*/
private function save_product_shipping_data($product, $data)
{
// Virtual.
if (isset($data['virtual']) && true === $data['virtual']) {
$product->set_weight('');
$product->set_height('');
$product->set_length('');
$product->set_width('');
} else {
if (isset($data['weight'])) {
$product->set_weight($data['weight']);
}
// Height.
if (isset($data['dimensions']['height'])) {
$product->set_height($data['dimensions']['height']);
}
// Width.
if (isset($data['dimensions']['width'])) {
$product->set_width($data['dimensions']['width']);
}
// Length.
if (isset($data['dimensions']['length'])) {
$product->set_length($data['dimensions']['length']);
}
}
// Shipping class.
if (isset($data['shipping_class'])) {
$shipping_class_term = get_term_by('slug', wc_clean($data['shipping_class']), 'product_shipping_class');
if ($shipping_class_term) {
$product->set_shipping_class_id($shipping_class_term->term_id);
}
}
return $product;
}
示例3: bulk_edit_save
/**
* Bulk edit.
*
* @param integer $post_id
* @param WC_Product $product
*/
public function bulk_edit_save($post_id, $product)
{
$old_regular_price = $product->get_regular_price();
$old_sale_price = $product->get_sale_price();
// Save fields
if (!empty($_REQUEST['change_weight']) && isset($_REQUEST['_weight'])) {
$product->set_weight(wc_clean(stripslashes($_REQUEST['_weight'])));
}
if (!empty($_REQUEST['change_dimensions'])) {
if (isset($_REQUEST['_length'])) {
$product->set_length(wc_clean(stripslashes($_REQUEST['_length'])));
}
if (isset($_REQUEST['_width'])) {
$product->set_width(wc_clean(stripslashes($_REQUEST['_width'])));
}
if (isset($_REQUEST['_height'])) {
$product->set_height(wc_clean(stripslashes($_REQUEST['_height'])));
}
}
if (!empty($_REQUEST['_tax_status'])) {
$product->set_tax_status(wc_clean($_REQUEST['_tax_status']));
}
if (!empty($_REQUEST['_tax_class'])) {
$tax_class = wc_clean($_REQUEST['_tax_class']);
if ('standard' == $tax_class) {
$tax_class = '';
}
$product->set_tax_class($tax_class);
}
if (!empty($_REQUEST['_shipping_class'])) {
$shipping_class = '_no_shipping_class' == $_REQUEST['_shipping_class'] ? '' : wc_clean($_REQUEST['_shipping_class']);
$shipping_class_id = $data_store->get_shipping_class_id_by_slug($shipping_class);
if ($shipping_class_id) {
$product->set_shipping_class_id($shipping_class_id);
}
}
if (!empty($_REQUEST['_visibility'])) {
$product->set_catalog_visibility(wc_clean($_REQUEST['_visibility']));
}
if (!empty($_REQUEST['_featured'])) {
$product->set_featured(stripslashes($_REQUEST['_featured']));
}
// Sold Individually
if (!empty($_REQUEST['_sold_individually'])) {
if ('yes' === $_REQUEST['_sold_individually']) {
$product->set_sold_individually('yes');
} else {
$product->set_sold_individually('');
}
}
// Handle price - remove dates and set to lowest
$change_price_product_types = apply_filters('woocommerce_bulk_edit_save_price_product_types', array('simple', 'external'));
$can_product_type_change_price = false;
foreach ($change_price_product_types as $product_type) {
if ($product->is_type($product_type)) {
$can_product_type_change_price = true;
break;
}
}
if ($can_product_type_change_price) {
$price_changed = false;
if (!empty($_REQUEST['change_regular_price'])) {
$change_regular_price = absint($_REQUEST['change_regular_price']);
$regular_price = esc_attr(stripslashes($_REQUEST['_regular_price']));
switch ($change_regular_price) {
case 1:
$new_price = $regular_price;
break;
case 2:
if (strstr($regular_price, '%')) {
$percent = str_replace('%', '', $regular_price) / 100;
$new_price = $old_regular_price + round($old_regular_price * $percent, wc_get_price_decimals());
} else {
$new_price = $old_regular_price + $regular_price;
}
break;
case 3:
if (strstr($regular_price, '%')) {
$percent = str_replace('%', '', $regular_price) / 100;
$new_price = max(0, $old_regular_price - round($old_regular_price * $percent, wc_get_price_decimals()));
} else {
$new_price = max(0, $old_regular_price - $regular_price);
}
break;
default:
break;
}
if (isset($new_price) && $new_price != $old_regular_price) {
$price_changed = true;
$new_price = round($new_price, wc_get_price_decimals());
$product->set_regular_price($new_price);
}
}
if (!empty($_REQUEST['change_sale_price'])) {
//.........这里部分代码省略.........