本文整理汇总了PHP中wc_delete_shop_order_transients函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_delete_shop_order_transients函数的具体用法?PHP wc_delete_shop_order_transients怎么用?PHP wc_delete_shop_order_transients使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_delete_shop_order_transients函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clear_transients
/**
* Clear the product/shop transients cache.
*
* ## EXAMPLES
*
* wp wc tool clear_transients
*
* @since 2.5.0
*/
public function clear_transients($args, $assoc_args)
{
wc_delete_product_transients();
wc_delete_shop_order_transients();
WC_Cache_Helper::get_transient_version('shipping', true);
WP_CLI::success('Product transients and shop order transients were cleared.');
}
示例2: plugin_registration_hook
/**
* Run on plugin activation
*/
static function plugin_registration_hook()
{
// TaxJar requires at least version 5.3 of PHP
if (version_compare(PHP_VERSION, '5.3', '<')) {
exit(sprintf('<strong>TaxJar requires PHP 5.3 or higher. You are currently using %s.</strong>', PHP_VERSION));
}
// WooCommerce must be activated for TaxJar to activate
if (!class_exists('Woocommerce')) {
exit('<strong>Please activate WooCommerce before activating TaxJar.</strong>');
}
global $wpdb;
// Clear all transients
wc_delete_product_transients();
wc_delete_shop_order_transients();
WC_Cache_Helper::get_transient_version('shipping', true);
// Clear all expired transients
/*
* Deletes all expired transients. The multi-table delete syntax is used
* to delete the transient record from table a, and the corresponding
* transient_timeout record from table b.
*
* Based on code inside core's upgrade_network() function.
*/
$sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\r\n \tWHERE a.option_name LIKE %s\r\n \tAND a.option_name NOT LIKE %s\r\n \tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\r\n \tAND b.option_value < %d";
$rows = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time()));
$sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\r\n \tWHERE a.option_name LIKE %s\r\n \tAND a.option_name NOT LIKE %s\r\n \tAND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )\r\n \tAND b.option_value < %d";
$rows2 = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', time()));
// Export Tax Rates
$current_class = '';
$rates = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates\r\n ORDER BY tax_rate_order\r\n LIMIT %d, %d\r\n ", 0, 10000));
ob_start();
$header = __('Country Code', 'woocommerce') . ',' . __('State Code', 'woocommerce') . ',' . __('ZIP/Postcode', 'woocommerce') . ',' . __('City', 'woocommerce') . ',' . __('Rate %', 'woocommerce') . ',' . __('Tax Name', 'woocommerce') . ',' . __('Priority', 'woocommerce') . ',' . __('Compound', 'woocommerce') . ',' . __('Shipping', 'woocommerce') . ',' . __('Tax Class', 'woocommerce') . "\n";
echo $header;
foreach ($rates as $rate) {
if ($rate->tax_rate_country) {
echo esc_attr($rate->tax_rate_country);
} else {
echo '*';
}
echo ',';
if ($rate->tax_rate_country) {
echo esc_attr($rate->tax_rate_state);
} else {
echo '*';
}
echo ',';
$locations = $wpdb->get_col($wpdb->prepare("SELECT location_code FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id));
if ($locations) {
echo esc_attr(implode('; ', $locations));
} else {
echo '*';
}
echo ',';
$locations = $wpdb->get_col($wpdb->prepare("SELECT location_code FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id));
if ($locations) {
echo esc_attr(implode('; ', $locations));
} else {
echo '*';
}
echo ',';
if ($rate->tax_rate) {
echo esc_attr($rate->tax_rate);
} else {
echo '0';
}
echo ',';
if ($rate->tax_rate_name) {
echo esc_attr($rate->tax_rate_name);
} else {
echo '*';
}
echo ',';
if ($rate->tax_rate_priority) {
echo esc_attr($rate->tax_rate_priority);
} else {
echo '1';
}
echo ',';
if ($rate->tax_rate_compound) {
echo esc_attr($rate->tax_rate_compound);
} else {
echo '0';
}
echo ',';
if ($rate->tax_rate_shipping) {
echo esc_attr($rate->tax_rate_shipping);
} else {
echo '0';
}
echo ',';
echo "\n";
}
$csv = ob_get_contents();
ob_end_clean();
$upload_dir = wp_upload_dir();
file_put_contents($upload_dir['basedir'] . '/taxjar-wc_tax_rates-' . date('m-d-Y') . '-' . time() . '.csv', $csv);
// Delete All tax rates
//.........这里部分代码省略.........
示例3: update_status
/**
* Updates status of order
*
* @param string $new_status Status to change the order to. No internal wc- prefix is required.
* @param string $note (default: '') Optional note to add
* @param bool $manual is this a manual order status change?
*/
public function update_status($new_status, $note = '', $manual = false)
{
if (!$this->id) {
return;
}
// Standardise status names.
$new_status = 'wc-' === substr($new_status, 0, 3) ? substr($new_status, 3) : $new_status;
$old_status = $this->get_status();
// Only update if they differ - and ensure post_status is a 'wc' status.
if ($new_status !== $old_status || !in_array($this->post_status, array_keys(wc_get_order_statuses()))) {
// Update the order
wp_update_post(array('ID' => $this->id, 'post_status' => 'wc-' . $new_status));
$this->post_status = 'wc-' . $new_status;
$this->add_order_note(trim($note . ' ' . sprintf(__('Order status changed from %s to %s.', 'woocommerce'), wc_get_order_status_name($old_status), wc_get_order_status_name($new_status))), 0, $manual);
// Status was changed
do_action('woocommerce_order_status_' . $new_status, $this->id);
do_action('woocommerce_order_status_' . $old_status . '_to_' . $new_status, $this->id);
do_action('woocommerce_order_status_changed', $this->id, $old_status, $new_status);
switch ($new_status) {
case 'completed':
// Record the sales
$this->record_product_sales();
// Increase coupon usage counts
$this->increase_coupon_usage_counts();
// Record the completed date of the order
update_post_meta($this->id, '_completed_date', current_time('mysql'));
// Update reports
wc_delete_shop_order_transients($this->id);
break;
case 'processing':
case 'on-hold':
// Record the sales
$this->record_product_sales();
// Increase coupon usage counts
$this->increase_coupon_usage_counts();
// Update reports
wc_delete_shop_order_transients($this->id);
break;
case 'cancelled':
// If the order is cancelled, restore used coupons
$this->decrease_coupon_usage_counts();
// Update reports
wc_delete_shop_order_transients($this->id);
break;
}
}
}
示例4: save
/**
* Save meta box data
*/
public static function save($post_id, $post)
{
global $wpdb;
self::init_address_fields();
// Add key
add_post_meta($post_id, '_order_key', uniqid('order_'), true);
// Update meta
update_post_meta($post_id, '_customer_user', absint($_POST['customer_user']));
if (self::$billing_fields) {
foreach (self::$billing_fields as $key => $field) {
if (!isset($field['id'])) {
$field['id'] = '_billing_' . $key;
}
update_post_meta($post_id, $field['id'], wc_clean($_POST[$field['id']]));
}
}
if (self::$shipping_fields) {
foreach (self::$shipping_fields as $key => $field) {
if (!isset($field['id'])) {
$field['id'] = '_shipping_' . $key;
}
update_post_meta($post_id, $field['id'], wc_clean($_POST[$field['id']]));
}
}
if (isset($_POST['_transaction_id'])) {
update_post_meta($post_id, '_transaction_id', wc_clean($_POST['_transaction_id']));
}
// Payment method handling
if (get_post_meta($post_id, '_payment_method', true) !== stripslashes($_POST['_payment_method'])) {
$methods = WC()->payment_gateways->payment_gateways();
$payment_method = wc_clean($_POST['_payment_method']);
$payment_method_title = $payment_method;
if (isset($methods) && isset($methods[$payment_method])) {
$payment_method_title = $methods[$payment_method]->get_title();
}
update_post_meta($post_id, '_payment_method', $payment_method);
update_post_meta($post_id, '_payment_method_title', $payment_method_title);
}
// Update date
if (empty($_POST['order_date'])) {
$date = current_time('timestamp');
} else {
$date = strtotime($_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00');
}
$date = date_i18n('Y-m-d H:i:s', $date);
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_date = %s, post_date_gmt = %s WHERE ID = %s", $date, get_gmt_from_date($date), $post_id));
// Order data saved, now get it so we can manipulate status
$order = wc_get_order($post_id);
// Order status
$order->update_status($_POST['order_status']);
wc_delete_shop_order_transients($post_id);
}
示例5: delete_refund
/**
* Delete a refund
*/
public static function delete_refund()
{
check_ajax_referer('order-item', 'security');
if (!current_user_can('edit_shop_orders')) {
die(-1);
}
$refund_id = absint($_POST['refund_id']);
if ($refund_id && 'shop_order_refund' === get_post_type($refund_id)) {
$order_id = wp_get_post_parent_id($refund_id);
wc_delete_shop_order_transients($order_id);
wp_delete_post($refund_id);
do_action('woocommerce_refund_deleted', $refund_id, $order_id);
}
die;
}
示例6: wc_order_fully_refunded
/**
* When refunding an order, create a refund line item if the partial refunds do not match order total.
*
* This is manual; no gateway refund will be performed.
*
* @since 2.4
* @param int $order_id
*/
function wc_order_fully_refunded($order_id)
{
$order = wc_get_order($order_id);
$max_refund = wc_format_decimal($order->get_total() - $order->get_total_refunded());
if (!$max_refund) {
return;
}
// Create the refund object
$refund = wc_create_refund(array('amount' => $max_refund, 'reason' => __('Order Fully Refunded', 'woocommerce'), 'order_id' => $order_id, 'line_items' => array()));
wc_delete_shop_order_transients($order_id);
}
示例7: update_status
/**
* Updates status of order
*
* @access public
* @param string $new_status_slug Status to change the order to
* @param string $note (default: '') Optional note to add
* @return void
*/
public function update_status($new_status_slug, $note = '')
{
if ($note) {
$note .= ' ';
}
$old_status = get_term_by('slug', sanitize_title($this->status), 'shop_order_status');
$new_status = get_term_by('slug', sanitize_title($new_status_slug), 'shop_order_status');
if ($new_status) {
wp_set_object_terms($this->id, array($new_status->slug), 'shop_order_status', false);
if ($this->id && $this->status != $new_status->slug) {
// Status was changed
do_action('woocommerce_order_status_' . $new_status->slug, $this->id);
do_action('woocommerce_order_status_' . $this->status . '_to_' . $new_status->slug, $this->id);
do_action('woocommerce_order_status_changed', $this->id, $this->status, $new_status->slug);
if ($old_status) {
$this->add_order_note($note . sprintf(__('Order status changed from %s to %s.', 'woocommerce'), __($old_status->name, 'woocommerce'), __($new_status->name, 'woocommerce')));
}
// Record the completed date of the order
if ('completed' == $new_status->slug) {
update_post_meta($this->id, '_completed_date', current_time('mysql'));
}
if ('processing' == $new_status->slug || 'completed' == $new_status->slug || 'on-hold' == $new_status->slug) {
// Record the sales
$this->record_product_sales();
// Increase coupon usage counts
$this->increase_coupon_usage_counts();
}
// If the order is cancelled, restore used coupons
if ('cancelled' == $new_status->slug) {
$this->decrease_coupon_usage_counts();
}
// Update last modified
wp_update_post(array('ID' => $this->id));
$this->status = $new_status->slug;
}
}
wc_delete_shop_order_transients($this->id);
}
示例8: untrash_post
/**
* woocommerce_untrash_post function.
*
* @param mixed $id
*/
public function untrash_post($id)
{
global $wpdb;
if ($id > 0) {
$post_type = get_post_type($id);
if (in_array($post_type, wc_get_order_types('order-count'))) {
// Delete count - meta doesn't work on trashed posts
$user_id = get_post_meta($id, '_customer_user', true);
if ($user_id > 0) {
update_user_meta($user_id, '_order_count', '');
update_user_meta($user_id, '_money_spent', '');
}
$refunds = $wpdb->get_results($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id));
foreach ($refunds as $refund) {
$wpdb->update($wpdb->posts, array('post_status' => 'wc-completed'), array('ID' => $refund->ID));
}
delete_transient('woocommerce_processing_order_count');
wc_delete_shop_order_transients($id);
}
}
}
示例9: sync
//.........这里部分代码省略.........
if ($transaction_id) {
update_post_meta($order_id, '_payment_method', 'paypal');
update_post_meta($order_id, '_payment_method_title', __('PayPal', 'woocommerce'));
update_post_meta($order_id, '_transaction_id', $transaction_id);
} else {
update_post_meta($order_id, '_payment_method', 'bacs');
update_post_meta($order_id, '_payment_method_title', __('BACS', 'woocommerce'));
}
// payment_complete
add_post_meta($order_id, '_paid_date', current_time('mysql'), true);
if (!get_post_meta($order_id, '_order_stock_reduced', true)) {
$order->reduce_order_stock();
}
}
}
foreach ($address_data as $key => $value) {
update_post_meta($order_id, '_' . $key, $value);
}
$order->remove_order_items('tax');
$order->add_tax(1, $tax, $shipping_tax);
$order->set_total($shipping, 'shipping');
$order->set_total($shipping_tax, 'shipping_tax');
$order->set_total($cart_discount, 'cart_discount');
$order->set_total($cart_discount_tax, 'cart_discount_tax');
$order->set_total($tax, 'tax');
$order->set_total($total, 'total');
if ($ordercontent->orderstate == 'cancelled') {
if (!$order->has_status('cancelled')) {
// update_status
$order->post_status = 'wc-cancelled';
$update_post_data = array('ID' => $order_id, 'post_status' => 'wc-cancelled', 'post_date' => current_time('mysql', 0), 'post_date_gmt' => current_time('mysql', 1));
wp_update_post($update_post_data);
$order->decrease_coupon_usage_counts();
wc_delete_shop_order_transients($order_id);
}
} else {
if ($ordercontent->orderstate == 'inprogress' || $ordercontent->orderstate == 'processing') {
if ($ordercontent->paymentstatus == 'complete') {
if (!$order->has_status('processing')) {
// update_status
$order->post_status = 'wc-processing';
$update_post_data = array('ID' => $order_id, 'post_status' => 'wc-processing', 'post_date' => current_time('mysql', 0), 'post_date_gmt' => current_time('mysql', 1));
wp_update_post($update_post_data);
}
} else {
if (!$order->has_status('pending')) {
// update_status
$order->post_status = 'wc-pending';
$update_post_data = array('ID' => $order_id, 'post_status' => 'wc-pending', 'post_date' => current_time('mysql', 0), 'post_date_gmt' => current_time('mysql', 1));
wp_update_post($update_post_data);
}
}
} else {
if ($ordercontent->orderstate == 'complete') {
if (!$order->has_status('completed')) {
// update_status
$order->post_status = 'wc-completed';
$update_post_data = array('ID' => $order_id, 'post_status' => 'wc-completed', 'post_date' => current_time('mysql', 0), 'post_date_gmt' => current_time('mysql', 1));
wp_update_post($update_post_data);
$order->record_product_sales();
$order->increase_coupon_usage_counts();
update_post_meta($order_id, '_completed_date', current_time('mysql'));
wc_delete_shop_order_transients($order_id);
}
}
}
示例10: delete_subscription
/**
* Delete subscription
*
* @since 2.0
*/
public function delete_subscription($subscription_id, $force = false)
{
$subscription_id = $this->validate_request($subscription_id, $this->post_type, 'delete');
if (is_wp_error($subscription_id)) {
return $subscription_id;
}
wc_delete_shop_order_transients($subscription_id);
do_action('woocommerce_api_delete_subscription', $subscription_id, $this);
return $this->delete($subscription_id, 'subscription', 'true' === $force);
}
示例11: save
/**
* Save meta box data.
*
* @param int $post_id
* @param WP_Post $post
*/
public static function save($post_id, $post)
{
global $wpdb;
self::init_address_fields();
// Ensure gateways are loaded in case they need to insert data into the emails
WC()->payment_gateways();
WC()->shipping();
$customer_changed = false;
// Add key
add_post_meta($post_id, '_order_key', uniqid('order_'), true);
// Update meta
if (update_post_meta($post_id, '_customer_user', absint($_POST['customer_user']))) {
$customer_changed = true;
}
if (!empty(self::$billing_fields)) {
foreach (self::$billing_fields as $key => $field) {
if (!isset($field['id'])) {
$field['id'] = '_billing_' . $key;
}
if (update_post_meta($post_id, $field['id'], wc_clean($_POST[$field['id']]))) {
$customer_changed = true;
}
}
}
if (!empty(self::$shipping_fields)) {
foreach (self::$shipping_fields as $key => $field) {
if (!isset($field['id'])) {
$field['id'] = '_shipping_' . $key;
}
if (update_post_meta($post_id, $field['id'], wc_clean($_POST[$field['id']]))) {
$customer_changed = true;
}
}
}
if (isset($_POST['_transaction_id'])) {
update_post_meta($post_id, '_transaction_id', wc_clean($_POST['_transaction_id']));
}
// Payment method handling
if (get_post_meta($post_id, '_payment_method', true) !== stripslashes($_POST['_payment_method'])) {
$methods = WC()->payment_gateways->payment_gateways();
$payment_method = wc_clean($_POST['_payment_method']);
$payment_method_title = $payment_method;
if (isset($methods) && isset($methods[$payment_method])) {
$payment_method_title = $methods[$payment_method]->get_title();
}
update_post_meta($post_id, '_payment_method', $payment_method);
update_post_meta($post_id, '_payment_method_title', $payment_method_title);
}
// Update date
if (empty($_POST['order_date'])) {
$date = current_time('timestamp');
} else {
$date = strtotime($_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00');
}
$date = date_i18n('Y-m-d H:i:s', $date);
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_date = %s, post_date_gmt = %s WHERE ID = %s", $date, get_gmt_from_date($date), $post_id));
clean_post_cache($post_id);
// If customer changed, update any downloadable permissions
if ($customer_changed) {
$wpdb->update($wpdb->prefix . "woocommerce_downloadable_product_permissions", array('user_id' => absint(get_post_meta($post->ID, '_customer_user', true)), 'user_email' => wc_clean(get_post_meta($post->ID, '_billing_email', true))), array('order_id' => $post_id), array('%d', '%s'), array('%d'));
}
// Order data saved, now get it so we can manipulate status
$order = wc_get_order($post_id);
// Order status
$order->update_status($_POST['order_status'], '', true);
wc_delete_shop_order_transients($post_id);
}
示例12: clear_caches
/**
* Clear any caches.
*
* @param WC_Order
* @since 2.7.0
*/
protected function clear_caches(&$order)
{
clean_post_cache($order->get_id());
wc_delete_shop_order_transients($order);
}
示例13: refund_line_items
/**
* Handle a refund via the edit order screen
*/
public static function refund_line_items()
{
ob_start();
check_ajax_referer('order-item', 'security');
$order_id = absint($_POST['order_id']);
$refund_amount = wc_format_decimal(sanitize_text_field($_POST['refund_amount']));
$refund_reason = sanitize_text_field($_POST['refund_reason']);
$line_item_qtys = json_decode(sanitize_text_field(stripslashes($_POST['line_item_qtys'])), true);
$line_item_totals = json_decode(sanitize_text_field(stripslashes($_POST['line_item_totals'])), true);
$line_item_tax_totals = json_decode(sanitize_text_field(stripslashes($_POST['line_item_tax_totals'])), true);
$api_refund = $_POST['api_refund'] === 'true' ? true : false;
$restock_refunded_items = $_POST['restock_refunded_items'] === 'true' ? true : false;
$refund = false;
try {
// Validate that the refund can occur
$order = wc_get_order($order_id);
$order_items = $order->get_items();
$max_refund = $order->get_total() - $order->get_total_refunded();
if (!$refund_amount || $max_refund < $refund_amount) {
throw new exception(__('Invalid refund amount', 'woocommerce'));
}
// Prepare line items which we are refunding
$line_items = array();
$item_ids = array_unique(array_merge(array_keys($line_item_qtys, $line_item_totals)));
foreach ($item_ids as $item_id) {
$line_items[$item_id] = array('qty' => 0, 'refund_total' => 0, 'refund_tax' => array());
}
foreach ($line_item_qtys as $item_id => $qty) {
$line_items[$item_id]['qty'] = max($qty, 0);
if ($restock_refunded_items && $qty && isset($order_items[$item_id])) {
$order_item = $order_items[$item_id];
$_product = $order->get_product_from_item($order_item);
if ($_product && $_product->exists() && $_product->managing_stock()) {
$old_stock = $_product->stock;
$new_quantity = $_product->increase_stock($qty);
$order->add_order_note(sprintf(__('Item #%s stock increased from %s to %s.', 'woocommerce'), $order_item['product_id'], $old_stock, $new_quantity));
}
}
}
foreach ($line_item_totals as $item_id => $total) {
$line_items[$item_id]['refund_total'] = wc_format_decimal($total);
}
foreach ($line_item_tax_totals as $item_id => $tax_totals) {
$line_items[$item_id]['refund_tax'] = array_map('wc_format_decimal', $tax_totals);
}
// Create the refund object
$refund = wc_create_refund(array('amount' => $refund_amount, 'reason' => $refund_reason, 'order_id' => $order_id, 'line_items' => $line_items));
if (is_wp_error($refund)) {
throw new Exception($refund->get_error_message());
}
// Refund via API
if ($api_refund) {
if (WC()->payment_gateways()) {
$payment_gateways = WC()->payment_gateways->payment_gateways();
}
if (isset($payment_gateways[$order->payment_method]) && $payment_gateways[$order->payment_method]->supports('refunds')) {
$result = $payment_gateways[$order->payment_method]->process_refund($order_id, $refund_amount, $refund_reason);
if (is_wp_error($result)) {
throw new Exception($result->get_error_message());
} elseif (!$result) {
throw new Exception(__('Refund failed', 'woocommerce'));
}
}
}
// Clear transients
wc_delete_shop_order_transients($order_id);
wp_send_json(true);
} catch (Exception $e) {
if ($refund && is_a($refund, 'WC_Order_Refund')) {
wp_delete_post($refund->id, true);
}
wp_send_json(array('error' => $e->getMessage()));
}
}
示例14: untrash_post
/**
* woocommerce_untrash_post function.
*
* @param mixed $id
*/
public static function untrash_post($id)
{
global $wpdb;
if ($id > 0) {
$post_type = get_post_type($id);
if (in_array($post_type, wc_get_order_types('order-count'))) {
$refunds = $wpdb->get_results($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'shop_order_refund' AND post_parent = %d", $id));
foreach ($refunds as $refund) {
$wpdb->update($wpdb->posts, array('post_status' => 'wc-completed'), array('ID' => $refund->ID));
}
delete_transient('woocommerce_processing_order_count');
wc_delete_shop_order_transients($id);
} elseif ('product' === $post_type) {
// Check if SKU is valid before untrash the product.
$sku = get_post_meta($id, '_sku', true);
if (!empty($sku)) {
if (!wc_product_has_unique_sku($id, $sku)) {
update_post_meta($id, '_sku', '');
}
}
}
}
}
示例15: status_tools
/**
* Handles output of tools
*/
public static function status_tools()
{
global $wpdb;
$tools = self::get_tools();
if (!empty($_GET['action']) && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'debug_action')) {
switch ($_GET['action']) {
case 'clear_transients':
wc_delete_product_transients();
wc_delete_shop_order_transients();
WC_Cache_Helper::get_transient_version('shipping', true);
echo '<div class="updated"><p>' . __('Product Transients Cleared', 'woocommerce') . '</p></div>';
break;
case 'clear_expired_transients':
/*
* Deletes all expired transients. The multi-table delete syntax is used
* to delete the transient record from table a, and the corresponding
* transient_timeout record from table b.
*
* Based on code inside core's upgrade_network() function.
*/
$sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\r\n\t\t\t\t\t\tWHERE a.option_name LIKE %s\r\n\t\t\t\t\t\tAND a.option_name NOT LIKE %s\r\n\t\t\t\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\r\n\t\t\t\t\t\tAND b.option_value < %d";
$rows = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time()));
$sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\r\n\t\t\t\t\t\tWHERE a.option_name LIKE %s\r\n\t\t\t\t\t\tAND a.option_name NOT LIKE %s\r\n\t\t\t\t\t\tAND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )\r\n\t\t\t\t\t\tAND b.option_value < %d";
$rows2 = $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_') . '%', $wpdb->esc_like('_site_transient_timeout_') . '%', time()));
echo '<div class="updated"><p>' . sprintf(__('%d Transients Rows Cleared', 'woocommerce'), $rows + $rows2) . '</p></div>';
break;
case 'reset_roles':
// Remove then re-add caps and roles
WC_Install::remove_roles();
WC_Install::create_roles();
echo '<div class="updated"><p>' . __('Roles successfully reset', 'woocommerce') . '</p></div>';
break;
case 'recount_terms':
$product_cats = get_terms('product_cat', array('hide_empty' => false, 'fields' => 'id=>parent'));
_wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false);
$product_tags = get_terms('product_tag', array('hide_empty' => false, 'fields' => 'id=>parent'));
_wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false);
echo '<div class="updated"><p>' . __('Terms successfully recounted', 'woocommerce') . '</p></div>';
break;
case 'clear_sessions':
$wpdb->query("\r\n\t\t\t\t\t\tDELETE FROM {$wpdb->options}\r\n\t\t\t\t\t\tWHERE option_name LIKE '_wc_session_%' OR option_name LIKE '_wc_session_expires_%'\r\n\t\t\t\t\t");
wp_cache_flush();
echo '<div class="updated"><p>' . __('Sessions successfully cleared', 'woocommerce') . '</p></div>';
break;
case 'install_pages':
WC_Install::create_pages();
echo '<div class="updated"><p>' . __('All missing WooCommerce pages was installed successfully.', 'woocommerce') . '</p></div>';
break;
case 'delete_taxes':
$wpdb->query("TRUNCATE " . $wpdb->prefix . "woocommerce_tax_rates");
$wpdb->query("TRUNCATE " . $wpdb->prefix . "woocommerce_tax_rate_locations");
echo '<div class="updated"><p>' . __('Tax rates successfully deleted', 'woocommerce') . '</p></div>';
break;
case 'reset_tracking':
delete_option('woocommerce_allow_tracking');
WC_Admin_Notices::add_notice('tracking');
echo '<div class="updated"><p>' . __('Usage tracking settings successfully reset.', 'woocommerce') . '</p></div>';
break;
default:
$action = esc_attr($_GET['action']);
if (isset($tools[$action]['callback'])) {
$callback = $tools[$action]['callback'];
$return = call_user_func($callback);
if ($return === false) {
if (is_array($callback)) {
echo '<div class="error"><p>' . sprintf(__('There was an error calling %s::%s', 'woocommerce'), get_class($callback[0]), $callback[1]) . '</p></div>';
} else {
echo '<div class="error"><p>' . sprintf(__('There was an error calling %s', 'woocommerce'), $callback) . '</p></div>';
}
}
}
break;
}
}
// Manual translation update messages
if (isset($_GET['translation_updated'])) {
WC_Language_Pack_Upgrader::language_update_messages();
}
// Display message if settings settings have been saved
if (isset($_REQUEST['settings-updated'])) {
echo '<div class="updated"><p>' . __('Your changes have been saved.', 'woocommerce') . '</p></div>';
}
include_once 'views/html-admin-page-status-tools.php';
}