本文整理汇总了PHP中wpshop_tools::wpshop_clean方法的典型用法代码示例。如果您正苦于以下问题:PHP wpshop_tools::wpshop_clean方法的具体用法?PHP wpshop_tools::wpshop_clean怎么用?PHP wpshop_tools::wpshop_clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wpshop_tools
的用法示例。
在下文中一共展示了wpshop_tools::wpshop_clean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reduce_product_stock_qty
/**
* Update quantity for a product
* @param integer $product_id The product we want to update quantity for
* @param decimal $qty The new quantity
*/
public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
{
global $wpdb;
$product = self::get_product_data($product_id);
/** Check if there is variation ***/
if (!empty($variation_id) && $variation_id != $product_id) {
$variation_post_type = get_post_type($variation_id);
if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
/** Check if variation def is combined **/
$variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
/** Get post meta of variation */
$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
$product = self::get_product_data($variation_id);
$product_id = $variation_id;
}
}
}
}
if (!empty($product)) {
$newQty = $product['product_stock'] - $qty;
$value_id = 0;
if ($newQty >= 0) {
$query = '
SELECT wp_wpshop__attribute_value_decimal.value_id
FROM wp_wpshop__attribute_value_decimal
LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id
WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock"
LIMIT 1
';
$value_id = $wpdb->get_var($query);
$update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
}
// Historic
$attribute_histo_content = array();
$attribute_histo_content['status'] = 'valid';
$attribute_histo_content['creation_date'] = current_time('mysql', 0);
$attribute_histo_content['creation_date_value'] = !empty($attribute_histo[0]->creation_date_value) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
$attribute_histo_content['original_value_id'] = $value_id;
$attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
$stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
$attribute_histo_content['attribute_id'] = $stock_atribute->id;
$attribute_histo_content['entity_id'] = $product_id;
$attribute_histo_content['value'] = $product['product_stock'];
$attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
$product_meta['product_stock'] = $newQty;
update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
}
}