Advertisement
businessdad

Currency Switcher - Clean up orders with "zero" totals

Jan 9th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1. /**
  2.  * Aelia Currency Switcher for WooCommerce.
  3.  * How to delete order meta in base currency for orders with a "zero" order total. The queries
  4.  * can be used to to clean up order totals, before running the recalculation described in
  5.  * the following knowledge base article: https://aelia.freshdesk.com/a/solutions/articles/3000052833
  6.  *
  7.  * IMPORTANT WARNING
  8.  * The queries delete data from the database, and the deletion is irreversible. We strongly
  9.  * recommend to run them on a staging copy of your database first, and to take a full backup
  10.  * of your data before running them on the production site.
  11.  *
  12.  * DISCLAIMER
  13.  * Aelia and any member of its staff are not responsible for any data loss or damage incurred
  14.  * when using the code, which you can use at your own risk.
  15.  *
  16.  * GPL DISCLAIMER
  17.  * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  18.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  19.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  20.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  21.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  22.  *
  23.  * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
  24.  */
  25.  
  26. -- Delete base currency amounts for order items
  27. -- from orders with a base currency total of zero or less
  28. -- SELECT
  29. -- meta_id,
  30. -- meta_key
  31. DELETE
  32. FROM
  33.  wp_woocommerce_order_itemmeta
  34. WHERE
  35.     (meta_id IN (
  36.         SELECT
  37.             OIM.meta_id
  38.         FROM
  39.                 wp_woocommerce_order_itemmeta OIM
  40.                 JOIN
  41.                 wp_woocommerce_order_items OI ON
  42.                     (OI.order_item_id = OIM.order_item_id)
  43.                 JOIN
  44.                 wp_postmeta PM ON
  45.                     (PM.post_id = OI.order_id) AND
  46.                     (PM.meta_key = '_order_total_base_currency') AND
  47.                     (PM.meta_value <= 0)
  48.         WHERE
  49.             OIM.meta_key like '%_base_currency'
  50.         ));
  51.  
  52. -- Delete base currency amounts for orders
  53. -- with a base currency total of zero or less.
  54. -- SELECT
  55. --     post_id
  56. DELETE
  57. FROM
  58.     wp_postmeta
  59. WHERE
  60.     (meta_key like '%_base_currency%') AND
  61.     (post_id IN (
  62.         SELECT
  63.             post_id
  64.         FROM
  65.                 wp_postmeta
  66.         WHERE
  67.                 (meta_key = '_order_total_base_currency') AND
  68.                 (meta_value <= 0)
  69.     ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement