CancelQuote.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. class Laybuy_Processes_CancelQuote extends Laybuy_Processes_AbstractProcess
  3. {
  4. public $quoteId;
  5. public $status;
  6. public function setQuoteId($quoteId)
  7. {
  8. $this->quoteId = $quoteId;
  9. return $this;
  10. }
  11. public function getQuoteId()
  12. {
  13. return $this->quoteId;
  14. }
  15. public function setStatus($status)
  16. {
  17. $this->status = $status;
  18. return $this;
  19. }
  20. public function getStatus()
  21. {
  22. return $this->status;
  23. }
  24. public function execute()
  25. {
  26. global $wpdb;
  27. $quote_id = $this->getQuoteId();
  28. $status = $this->getStatus();
  29. WC_Laybuy_Logger::log("Cancelling WP Quote with ID:{$quote_id}");
  30. # Mark the quote as cancelled.
  31. update_post_meta( $quote_id, 'status', $status );
  32. # Don't use `wp_trash_post` or `wp_delete_post`
  33. # because we don't want any hooks to fire.
  34. WC_Laybuy_Logger::log("Running DB query: 'DELETE FROM `{$wpdb->postmeta}` WHERE `post_id` = $quote_id'");
  35. WC_Laybuy_Logger::log($wpdb->query( $wpdb->prepare( "DELETE FROM `{$wpdb->postmeta}` WHERE `post_id` = %d", $quote_id ) ) . " row(s) deleted from `{$wpdb->postmeta}` table.");
  36. WC_Laybuy_Logger::log("Running DB query: 'DELETE FROM `{$wpdb->posts}` WHERE `ID` = $quote_id LIMIT 1'");
  37. WC_Laybuy_Logger::log($wpdb->query( $wpdb->prepare( "DELETE FROM `{$wpdb->posts}` WHERE `ID` = %d LIMIT 1", $quote_id ) ) . " row(s) deleted from `{$wpdb->posts}` table.");
  38. return true;
  39. }
  40. }