Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/StoreApi/Utilitie...
File: DraftOrderTrait.php
<?php
[0] Fix | Delete
namespace Automattic\WooCommerce\StoreApi\Utilities;
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* DraftOrderTrait
[4] Fix | Delete
*
[5] Fix | Delete
* Shared functionality for getting and setting draft order IDs from session.
[6] Fix | Delete
*/
[7] Fix | Delete
trait DraftOrderTrait {
[8] Fix | Delete
/**
[9] Fix | Delete
* Gets draft order data from the customer session.
[10] Fix | Delete
*
[11] Fix | Delete
* @return integer
[12] Fix | Delete
*/
[13] Fix | Delete
protected function get_draft_order_id() {
[14] Fix | Delete
if ( ! wc()->session ) {
[15] Fix | Delete
wc()->initialize_session();
[16] Fix | Delete
}
[17] Fix | Delete
return wc()->session->get( 'store_api_draft_order', 0 );
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Updates draft order data in the customer session.
[22] Fix | Delete
*
[23] Fix | Delete
* @param integer $order_id Draft order ID.
[24] Fix | Delete
*/
[25] Fix | Delete
protected function set_draft_order_id( $order_id ) {
[26] Fix | Delete
if ( ! wc()->session ) {
[27] Fix | Delete
wc()->initialize_session();
[28] Fix | Delete
}
[29] Fix | Delete
wc()->session->set( 'store_api_draft_order', $order_id );
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Uses the draft order ID to return an order object, if valid.
[34] Fix | Delete
*
[35] Fix | Delete
* @return \WC_Order|null;
[36] Fix | Delete
*/
[37] Fix | Delete
protected function get_draft_order() {
[38] Fix | Delete
$draft_order_id = $this->get_draft_order_id();
[39] Fix | Delete
$draft_order = $draft_order_id ? wc_get_order( $draft_order_id ) : false;
[40] Fix | Delete
[41] Fix | Delete
return $this->is_valid_draft_order( $draft_order ) ? $draft_order : null;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Whether the passed argument is a draft order or an order that is
[46] Fix | Delete
* pending/failed and the cart hasn't changed.
[47] Fix | Delete
*
[48] Fix | Delete
* @param \WC_Order $order_object Order object to check.
[49] Fix | Delete
* @return boolean Whether the order is valid as a draft order.
[50] Fix | Delete
*/
[51] Fix | Delete
protected function is_valid_draft_order( $order_object ) {
[52] Fix | Delete
if ( ! $order_object instanceof \WC_Order ) {
[53] Fix | Delete
return false;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
// Draft orders are okay.
[57] Fix | Delete
if ( $order_object->has_status( 'checkout-draft' ) ) {
[58] Fix | Delete
return true;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
// Pending and failed orders can be retried if the cart hasn't changed.
[62] Fix | Delete
if ( $order_object->needs_payment() && $order_object->has_cart_hash( wc()->cart->get_cart_hash() ) ) {
[63] Fix | Delete
return true;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
return false;
[67] Fix | Delete
}
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function