本文整理汇总了PHP中WC_Product::get_data_store方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::get_data_store方法的具体用法?PHP WC_Product::get_data_store怎么用?PHP WC_Product::get_data_store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::get_data_store方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quick_edit_save
/**
* Quick edit.
*
* @param integer $post_id
* @param WC_Product $product
*/
private function quick_edit_save($post_id, $product)
{
$data_store = $product->get_data_store();
$old_regular_price = $product->get_regular_price();
$old_sale_price = $product->get_sale_price();
// Save fields
if (isset($_REQUEST['_sku'])) {
$sku = $product->get_sku();
$new_sku = (string) wc_clean($_REQUEST['_sku']);
if ($new_sku !== $sku) {
if (!empty($new_sku)) {
$unique_sku = wc_product_has_unique_sku($post_id, $new_sku);
if ($unique_sku) {
$product->set_sku($new_sku);
}
} else {
$product->set_sku('');
}
}
}
if (isset($_REQUEST['_weight'])) {
$product->set_weight(wc_clean($_REQUEST['_weight']));
}
if (isset($_REQUEST['_length'])) {
$product->set_length(wc_clean($_REQUEST['_length']));
}
if (isset($_REQUEST['_width'])) {
$product->set_width(wc_clean($_REQUEST['_width']));
}
if (isset($_REQUEST['_height'])) {
$product->set_height(wc_clean($_REQUEST['_height']));
}
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 (isset($_REQUEST['_visibility'])) {
$product->set_catalog_visibility(wc_clean($_REQUEST['_visibility']));
}
if (isset($_REQUEST['_featured'])) {
$product->set_featured(true);
} else {
$product->set_featured(false);
}
if (isset($_REQUEST['_tax_status'])) {
$product->set_tax_status(wc_clean($_REQUEST['_tax_status']));
}
if (isset($_REQUEST['_tax_class'])) {
$product->set_tax_class(wc_clean($_REQUEST['_tax_class']));
}
if ($product->is_type('simple') || $product->is_type('external')) {
if (isset($_REQUEST['_regular_price'])) {
$new_regular_price = '' === $_REQUEST['_regular_price'] ? '' : wc_format_decimal($_REQUEST['_regular_price']);
$product->set_regular_price($new_regular_price);
} else {
$new_regular_price = null;
}
if (isset($_REQUEST['_sale_price'])) {
$new_sale_price = '' === $_REQUEST['_sale_price'] ? '' : wc_format_decimal($_REQUEST['_sale_price']);
$product->set_sale_price($new_sale_price);
} else {
$new_sale_price = null;
}
// Handle price - remove dates and set to lowest
$price_changed = false;
if (!is_null($new_regular_price) && $new_regular_price != $old_regular_price) {
$price_changed = true;
} elseif (!is_null($new_sale_price) && $new_sale_price != $old_sale_price) {
$price_changed = true;
}
if ($price_changed) {
$product->set_date_on_sale_to('');
$product->set_date_on_sale_from('');
}
}
// Handle Stock Data
$manage_stock = !empty($_REQUEST['_manage_stock']) && 'grouped' !== $product->get_type() ? 'yes' : 'no';
$backorders = !empty($_REQUEST['_backorders']) ? wc_clean($_REQUEST['_backorders']) : 'no';
$stock_status = !empty($_REQUEST['_stock_status']) ? wc_clean($_REQUEST['_stock_status']) : 'instock';
$stock_amount = 'yes' === $manage_stock ? wc_stock_amount($_REQUEST['_stock']) : '';
if ('yes' === get_option('woocommerce_manage_stock')) {
// Apply product type constraints to stock status
if ($product->is_type('external')) {
// External always in stock
$stock_status = 'instock';
} elseif ($product->is_type('variable')) {
// Stock status is always determined by children
foreach ($product->get_children() as $child_id) {
$child = wc_get_product($child_id);
if (!$product->get_manage_stock()) {
$child->set_stock_status($stock_status);
//.........这里部分代码省略.........
示例2: 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;
}
示例3: get_rating_counts_for_product
/**
* Get product rating count for a product. Please note this is not cached.
*
* @since 2.7.0
* @param WC_Product $product
* @return array of integers
*/
public static function get_rating_counts_for_product(&$product)
{
global $wpdb;
$counts = array();
$raw_counts = $wpdb->get_results($wpdb->prepare("\n\t\t\tSELECT meta_value, COUNT( * ) as meta_value_count FROM {$wpdb->commentmeta}\n\t\t\tLEFT JOIN {$wpdb->comments} ON {$wpdb->commentmeta}.comment_id = {$wpdb->comments}.comment_ID\n\t\t\tWHERE meta_key = 'rating'\n\t\t\tAND comment_post_ID = %d\n\t\t\tAND comment_approved = '1'\n\t\t\tAND meta_value > 0\n\t\t\tGROUP BY meta_value\n\t\t", $product->get_id()));
foreach ($raw_counts as $count) {
$counts[$count->meta_value] = absint($count->meta_value_count);
}
$product->set_rating_counts($counts);
$data_store = $product->get_data_store();
$data_store->update_rating_counts($product);
return $counts;
}