Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion includes/Core/Ecommerce/Platforms/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ public function orders( array $args = array() ) {
* Register post update hooks
*/
public function register_hooks() {
// New order created hook
add_action( 'woocommerce_new_order', array( $this, 'handle_order' ), 10, 2 );

// Order status changed hook (handles pending payment, completed, etc.)
add_action( 'woocommerce_order_status_changed', array( $this, 'handle_order' ), 10, 4 );

// Pending payment status specific hook
add_action( 'woocommerce_order_status_pending', array( $this, 'handle_pending_payment' ), 10, 1 );

add_action( 'woocommerce_order_refunded', array( $this, 'create_order_refund' ), 10, 2 );
add_action( 'woocommerce_refund_deleted', array( $this, 'delete_order_refund' ), 10, 2 );
add_action( 'after_delete_post', array( $this, 'delete' ), 10, 2 );
Expand All @@ -109,6 +117,37 @@ public function register_hooks() {
add_action( 'woocommerce_delete_product_variation', array( $this, 'delete_product_variation' ) );
}

/**
* Handling pending payment status
*
* @param int $order_id Order ID
*
* @return void
*/
public function handle_pending_payment( $order_id ) {
$order = wc_get_order( $order_id );

if ( ! $order ) {
return;
}

if ( ! $this->is_valid_order_item( $order->get_type() ) ) {
return;
}

if ( ! Settings::instance()->is_enabled() ) {
return;
}

$payload = OrderResource::single( $order );

wemail()->api
->send_json()
->ecommerce()
->orders( $order_id )
->put( $payload );
}

/**
* Handling order
*
Expand All @@ -117,7 +156,7 @@ public function register_hooks() {
* @param $status_to
* @param $order \WC_Order
*/
public function handle_order( $order_id, $status_from, $status_to, $order ) {
public function handle_order( $order_id, $order ) {
if ( ! $this->is_valid_order_item( $order->get_type() ) ) {
return;
}
Expand Down
Loading