Option for ‘Cash on Delivery’ to auto reduce stock

Q: Cash On Delivery do not auto reduce stock. I’d just post the requirement for auto reduce as a suggested new feature. My store only has single (or very limited) numbers of items and so I need them to be reduced straight away so that I don’t get multiple customers wanting to buy the same item. As I understood, the stock gets reduced but only after payment and this prevents people from ordering the entire store on COD. But, I’m willing to take this risk as this is my business requirement.

A: For obtaining the required, you can modify Jigoshop file: plugins/Jigoshop/Gateways/cod.php.

BE WARNED – Messing up in here can bring you entire site down. Therefore, follow the steps below:

1) first make a back up of the cod.php file: the simplest way to it is via FTP to copy + download the file to your PC

2) go to the WordPress dashboard:

  • select the Plugins tab

  • select the Editior

  • in the ‘Select Plugin To Edit’ dropdown, select Jigoshop and click ‘Select’

  • scroll down the file list till you find the cod.php file (may be easier to do ctrl-f and do a find for cod) and click the cod.php file

3) make a changes in the file cod.php:

  • there is a function called process_payment. Inside that comment out (put two slashes // before) the update status line:

    //$order->update_status('on-hold', __('Waiting for cash delivery', 'jigoshop'));
    
  • then insert the lines below:

    // Changed to process the order immediately so stock is reduced
    $order->update_status('processing');
    $order->payment_complete();
    

That will update the status and send mails. This customization WILL be lost on the next Jigoshop update though.

4) click ‘Update file’

5) after making changes DO NOT browse away from the editor, instead open a new window to view / test the changes as then if anything goes wrong you can fix it in the editor window still. If things do mess up you can always FTP the original cod.php version of the file back onto the server.