这是PHP代码的一个选项:
function change_price_by_type( $product_id, $price, $price_type) {
update_post_meta( $product_id, \'_\' . $price_type, $price );
}
function change_price_all_types( $product_id, $price ) {
change_price_by_type( $product_id, $price, \'price\' );
change_price_by_type( $product_id, $price, \'sale_price\' );
change_price_by_type( $product_id, $price, \'regular_price\');
}
function change_product_price( $product_id, $price ) {
change_price_all_types( $product_id, $price );
$product = wc_get_product( $product_id ); // Handling variable products
if ( $product->is_type( \'variable\' ) ) {
// RM: Get variations which are also out of stock
$args = array(
\'post_type\' => \'product_variation\',
\'post_status\' => array( \'private\', \'publish\' ),
\'numberposts\' => -1,
\'orderby\' => \'menu_order\',
\'order\' => \'asc\',
\'post_parent\' => $product_id // $post->ID
);
$variations = get_posts( $args );
foreach ( $variations as $variation ) {
change_price_all_types( $variation->ID, $price );
}
}
}
$args = array( \'post_type\' => \'product\', \'posts_per_page\' => 3000);
$products = get_posts( $args );
foreach($products as $product) {
change_product_price($product->ID, 9.99);
echo $product->ID;
}
exit;
然后转到phpMyAdmin并运行以下SQL查询(您可能需要更改表名,而不是wp\\u1)。
UPDATE `wp_postmeta`
SET `meta_value` = \'\'
WHERE `meta_key` IN (\'_sale_price\', \'_sale_price_dates_from\', \'_sale_price_dates_to\')
AND `post_id` IN
(SELECT `ID`
FROM `wp_posts`
WHERE `post_type` = \'product\'
AND `post_status` = \'publish\' );
清除缓存:
DELETE
FROM `wp_options`
WHERE (`option_name` LIKE \'_transient_wc_var_prices_%\'
OR `option_name` LIKE \'_transient_timeout_wc_var_prices_%\')
SQL代码取自:
http://www.technoedu.com/forums/topic/wordpress-solved-copy-woocommerce-products-sale-prices-to-regular-prices-and-reset-sale-prices/