wc_scheduled_sales

Function which handles the start and end of scheduled sales via cron.

Description

wc_scheduled_sales(); 

Usage

  1. if ( !function_exists( 'wc_scheduled_sales' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wc_scheduled_sales(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-product-functions.php  
  1. function wc_scheduled_sales() { 
  2. $data_store = WC_Data_Store::load( 'product' ); 
  3.  
  4. // Sales which are due to start 
  5. $product_ids = $data_store->get_starting_sales(); 
  6. if ( $product_ids ) { 
  7. foreach ( $product_ids as $product_id ) { 
  8. $product = wc_get_product( $product_id ); 
  9. $sale_price = $product->get_sale_price(); 
  10.  
  11. if ( $sale_price ) { 
  12. $product->set_price( $sale_price ); 
  13. $product->set_date_on_sale_from( '' ); 
  14. } else { 
  15. $product->set_date_on_sale_to( '' ); 
  16. $product->set_date_on_sale_from( '' ); 
  17.  
  18. $product->save(); 
  19.  
  20. delete_transient( 'wc_products_onsale' ); 
  21.  
  22. // Sales which are due to end 
  23. $product_ids = $data_store->get_ending_sales(); 
  24. if ( $product_ids ) { 
  25. foreach ( $product_ids as $product_id ) { 
  26. $product = wc_get_product( $product_id ); 
  27. $regular_price = $product->get_regular_price(); 
  28. $product->set_price( $regular_price ); 
  29. $product->set_sale_price( '' ); 
  30. $product->set_date_on_sale_to( '' ); 
  31. $product->set_date_on_sale_from( '' ); 
  32. $product->save(); 
  33.  
  34. WC_Cache_Helper::get_transient_version( 'product', true ); 
  35. delete_transient( 'wc_products_onsale' );