本文整理汇总了PHP中WC_Product::set_stock方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::set_stock方法的具体用法?PHP WC_Product::set_stock怎么用?PHP WC_Product::set_stock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::set_stock方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* Set stock level of the product.
*
* @param mixed $amount (default: null)
* @param string $mode can be set, add, or subtract
* @return int Stock
*/
function set_stock($amount = null, $mode = 'set')
{
// Empty total stock so its refreshed
$this->total_stock = '';
// Call parent set_stock
return parent::set_stock($amount, $mode);
}
示例2: set_stock
/**
* Set stock level of the product.
*
* @param mixed $amount (default: null)
* @param string $mode can be set, add, or subtract
* @return int Stock
*/
public function set_stock($amount = null, $mode = 'set')
{
$this->total_stock = '';
delete_transient('wc_product_total_stock_' . $this->id . WC_Cache_Helper::get_transient_version('product'));
return parent::set_stock($amount, $mode);
}
示例3: unset
/**
* Set stock level of the product variation.
* @param int $amount
* @param bool $force_variation_stock If true, the variation's stock will be updated and not the parents.
* @return int
* @todo Need to return 0 if is_null? Or something. Should not be just return.
*/
function set_stock($amount = null, $force_variation_stock = false)
{
if (is_null($amount)) {
return;
}
if ($amount === '' && $force_variation_stock) {
// If amount is an empty string, stock management is being turned off at variation level
$this->variation_has_stock = false;
$this->stock = '';
unset($this->manage_stock);
// Update meta
update_post_meta($this->variation_id, '_stock', '');
// Refresh parent prices
WC_Product_Variable::sync($this->id);
} elseif ($this->variation_has_stock || $force_variation_stock) {
// Update stock amount
$this->stock = intval($amount);
$this->variation_has_stock = true;
$this->manage_stock = 'yes';
// Update meta
update_post_meta($this->variation_id, '_stock', $this->stock);
// Clear total stock transient
delete_transient('wc_product_total_stock_' . $this->id);
// Check parents out of stock attribute
if (!$this->is_in_stock()) {
// Check parent
$parent_product = get_product($this->id);
// Only continue if the parent has backorders off and all children are stock managed and out of stock
if (!$parent_product->backorders_allowed() && $parent_product->get_total_stock() <= get_option('woocommerce_notify_no_stock_amount')) {
$all_managed = true;
if (sizeof($parent_product->get_children()) > 0) {
foreach ($parent_product->get_children() as $child_id) {
$stock = get_post_meta($child_id, '_stock', true);
if ($stock == '') {
$all_managed = false;
break;
}
}
}
if ($all_managed) {
$this->set_stock_status('outofstock');
}
}
} elseif ($this->is_in_stock()) {
$this->set_stock_status('instock');
}
// Refresh parent prices
WC_Product_Variable::sync($this->id);
// Trigger action
do_action('woocommerce_product_set_stock', $this);
return $this->get_stock_quantity();
} else {
return parent::set_stock($amount);
}
}
示例4: intval
/**
* Set stock level of the product.
*
* @access public
* @param mixed $amount (default: null)
* @return int Stock
*/
function set_stock($amount = null)
{
global $woocommerce;
if ($this->variation_has_stock) {
if ($this->managing_stock() && !is_null($amount)) {
$this->stock = intval($amount);
$this->total_stock = intval($amount);
update_post_meta($this->variation_id, '_stock', $this->stock);
$woocommerce->clear_product_transients($this->id);
// Clear transient
// Check parents out of stock attribute
if (!$this->is_in_stock()) {
// Check parent
$parent_product = get_product($this->id);
// Only continue if the parent has backorders off
if (!$parent_product->backorders_allowed() && $parent_product->get_total_stock() <= 0) {
$this->set_stock_status('outofstock');
}
} elseif ($this->is_in_stock()) {
$this->set_stock_status('instock');
}
return apply_filters('woocommerce_stock_amount', $this->stock);
}
} else {
return parent::set_stock($amount);
}
}
示例5: setStockToOne
function setStockToOne()
{
if (!function_exists('wc_update_product_stock')) {
require_once 'http://stage.hyzershop.com/wp-content/plugins/woocommerce/includes/wc-product-functions.php';
}
$variations = get_posts(array('posts_per_page' => -1, 'post_type' => 'product_variation', 'post_status' => 'publish'));
foreach ($variations as $product) {
$product_id = $product->ID;
$new_stock_level = 1;
$product = new WC_Product($product_id);
$product->set_stock($new_stock_level);
//wc_update_product_stock( $product_id, $new_stock_level );
}
}
示例6: set_stock
/**
* Set stock level of the product.
*
* @param mixed $amount (default: null)
* @param string $mode can be set, add, or subtract
* @return int Stock
*/
public function set_stock($amount = null, $mode = 'set')
{
$this->total_stock = '';
delete_transient('wc_product_total_stock_' . $this->id);
return parent::set_stock($amount, $mode);
}
开发者ID:sergioblanco86,项目名称:git-gitlab.com-kinivo-kinivo.com,代码行数:13,代码来源:class-wc-product-variable.php
示例7: woo_insert_update_data
//.........这里部分代码省略.........
foreach ($post_meta_key as $object) {
// ================================================================================================
// Code for enabling negative values for inline editing
// ================================================================================================
// if ( $object == '_sale_price' || $object == '_price' || $object == '_regular_price' ) {
// update_post_meta($wpdb->_real_escape($post_id), $wpdb->_real_escape($object), $wpdb->_real_escape($postarr[$object]) );
// continue;
// }
// ================================================================================================
if (isset($postarr[$object]) && $postarr[$object] > -1) {
// to skip query for blank value
//Code to handle the condition for the attribute visibility on product page issue while save action
if ($object == '_product_attributes' && isset($product_custom_fields['_product_attributes'][0])) {
continue;
}
if (empty($obj->id) || $obj->id == '') {
$query = "INSERT INTO {$wpdb->prefix}postmeta(post_id,meta_key,meta_value) values(" . $wpdb->_real_escape($post_id) . ", '" . $wpdb->_real_escape($object) . "', '" . $wpdb->_real_escape($postarr[$object]) . "')";
$var = $wpdb->query($query);
wp_set_object_terms($post_id, 'simple', 'product_type');
} else {
//$query = "UPDATE {$wpdb->prefix}postmeta SET meta_value = '".$wpdb->_real_escape($postarr[$object])."' WHERE post_id = " . $wpdb->_real_escape($post_id) . " AND meta_key = '" . $wpdb->_real_escape($object) . "'";
update_post_meta($wpdb->_real_escape($post_id), $wpdb->_real_escape($object), $wpdb->_real_escape($postarr[$object]));
if ($object == '_stock') {
if ($_POST['SM_IS_WOO21'] == "true" || $_POST['SM_IS_WOO22'] == "true") {
$woo_version = defined('WOOCOMMERCE_VERSION') ? WOOCOMMERCE_VERSION : $woocommerce->version;
if ($postarr['post_parent'] > 0) {
$woo_prod_obj_stock_status = new WC_Product_Variation($post_id);
} else {
$woo_prod_obj_stock_status = new WC_Product($post_id);
}
if (version_compare($woo_version, '2.4', ">=")) {
$woo_prod_obj_stock_status->check_stock_status();
} else {
$woo_prod_obj_stock_status->set_stock($wpdb->_real_escape($postarr[$object]));
}
}
}
}
}
}
//Code For updating the parent price of the product
if ($parent_id > 0) {
if ($_POST['SM_IS_WOO21'] == "true" || $_POST['SM_IS_WOO22'] == "true") {
WC_Product_Variable::sync($parent_id);
delete_transient('wc_product_children_' . $parent_id);
//added in woo24
} else {
variable_price_sync($parent_id);
}
}
} elseif ($_POST['active_module'] == 'Orders') {
foreach ($obj as $key => $value) {
if (in_array($key, $editable_fields)) {
if ($key == 'order_status') {
// $term_taxonomy_id = get_term_taxonomy_id ( $value );
// $query = "UPDATE {$wpdb->prefix}term_relationships SET term_taxonomy_id = " . $wpdb->_real_escape($term_taxonomy_id) . " WHERE object_id = " . $wpdb->_real_escape($obj->id) . ";";
// if ( $value == 'processing' || $value == 'completed' ) {
$order = new WC_Order($obj->id);
$order->update_status($value);
// }
} else {
$query = "UPDATE {$wpdb->prefix}postmeta SET meta_value = '" . $wpdb->_real_escape($value) . "' WHERE post_id = " . $wpdb->_real_escape($obj->id) . " AND meta_key = '" . $wpdb->_real_escape($key) . "';";
$wpdb->query($query);
}
}
}