kylebarrow
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce] WooCommerce Schedule Sale Price – Not workingWhen we were looking at a fix for products where the sale had already started, we found removing the scheduled sale start date then updating fixed the issue (sale price shown, shows on sale page) but we had well over 200 products affected by this bug (many with variations) so instead made a quick and dirty function that we could access via an ‘AJAX’ call to fix:
function fix_past_sales() { $is_admin = false; // Only allow shop admins to run this if (is_user_logged_in()) { $current_user = wp_get_current_user(); $current_user_roles = $current_user->roles; $admin_roles = array('administrator', 'editor', 'shop_manager'); foreach ($current_user_roles as $user_role) { if (in_array($user_role, $admin_roles, true)) { $is_admin = true; break; } }; } if (!$is_admin) { echo 'Invalid user'; return; } global $wpdb; $now = new DateTime(); // Get products with a sale start in the past $results = $wpdb->get_results("SELECT post_id, meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key='_sale_price_dates_from' AND meta_value < {$now->getTimestamp()}", OBJECT); echo '<pre>'; foreach($results as $result) { $product = wc_get_product($result->post_id); if ($product) { $product_name = $product->get_name(); $product_sale_start = date('Y-m-d H:i:s', $result->meta_value); // Remove the sale start $product->set_date_on_sale_from(''); $product->save(); echo "Removed sale start date $product_sale_start from $product_name\n"; } } echo '</pre>'; } add_action('wc_ajax_fix_past_sales', 'fix_past_sales');
When placed in your site theme functions.php this can be triggered by https://yoursitedomain.com/?wc-ajax=fix_past_sales
Worked for us but was a hot fix with limited QA and so comes with the usual use at own risk warning.
- This reply was modified 1 year, 2 months ago by kylebarrow.
- This reply was modified 1 year, 2 months ago by kylebarrow.
Forum: Plugins
In reply to: [WooCommerce] WooCommerce Schedule Sale Price – Not workingWe ran into the same issue (currently running 8.4.0) when we noticed scheduled sale products were not showing up on the sale page well after the schedule had passed ([sale_products] shortcode).
Looking at the product object, we can see the issue is with the price value. Here’s an example showing the bug with a simple product with past scheduled sale price:
WC_Product_Simple Object ( ... [price] => 1000 [regular_price] => 1000 [sale_price] => 700 [date_on_sale_from] => WC_DateTime Object ( [utc_offset:protected] => 0 [date] => 2023-12-19 00:00:00.000000 [timezone_type] => 3 [timezone] => Asia/Tokyo ) [date_on_sale_to] => ... )
The price has not been updated with the sale_price value although it is well past the scheduled time. Other posts alluded to an issue with the woocommerce_scheduled_sales cron event but we confirmed the event had run on time and we manually ran the event as well.
Diving into the DB, for the above product .._wc_product_meta_lookup table, the onsale boolean is false.
Curiously, variable products do show correct schedule sale prices although they still suffer the same issue with not showing on our sales page and as with simple products, the .._wc_product_meta_lookup table onsale boolean is also false.
- This reply was modified 1 year, 2 months ago by kylebarrow.
- This reply was modified 1 year, 2 months ago by kylebarrow.
- This reply was modified 1 year, 2 months ago by kylebarrow.