복붙노트

[WORDPRESS] WOOCOMMERCE - 자동 재입고 제품 [폐쇄]

WORDPRESS

WOOCOMMERCE - 자동 재입고 제품 [폐쇄]

해결법


  1. 1.COUPER_STOCK_DAILY라는 CRON 이벤트를 등록하고 일일 또는 요구 사항에 따라 실행되도록하십시오.

    COUPER_STOCK_DAILY라는 CRON 이벤트를 등록하고 일일 또는 요구 사항에 따라 실행되도록하십시오.

    // Add function to register event to WordPress init
    add_action( 'init', 'register_daily_stock_event');
    
    // Function which will register the event
    function register_daily_stock_event() {
        // Make sure this event hasn't been scheduled
        if( !wp_next_scheduled( 'increase_stock_daily' ) ) {
            // Schedule the event
            wp_schedule_event( time(), 'daily', 'increase_stock_daily' );
        }
    }   
    
    function increase_stock_daily() {
        $product = new WC_Product(10); // replace 10 with your own product ID
        if($product->get_total_stock() < 30) {
            $product->set_stock(30);
        }
    }
    
  2. from https://stackoverflow.com/questions/36984277/woocommerce-automatic-restock-a-product by cc-by-sa and MIT license