2015-03-03 11:38:05 +00:00
|
|
|
<?php
|
2017-11-24 18:57:45 +00:00
|
|
|
/**
|
|
|
|
* Class WC_Tests_Order_Functions file.
|
|
|
|
*
|
|
|
|
* @package WooCommerce/Tests
|
|
|
|
*/
|
2015-03-06 15:32:40 +00:00
|
|
|
|
2015-03-03 11:38:05 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Class Functions.
|
2017-11-24 18:57:45 +00:00
|
|
|
*
|
2015-03-06 15:32:40 +00:00
|
|
|
* @package WooCommerce\Tests\Order
|
|
|
|
* @since 2.3
|
2015-03-03 11:38:05 +00:00
|
|
|
*/
|
2016-03-23 12:14:13 +00:00
|
|
|
class WC_Tests_Order_Functions extends WC_Unit_Test_Case {
|
2015-03-03 11:38:05 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_get_order_statuses().
|
2015-03-03 11:38:05 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_statuses() {
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$order_statuses = apply_filters(
|
|
|
|
'wc_order_statuses', array(
|
|
|
|
'wc-pending' => _x( 'Pending payment', 'Order status', 'woocommerce' ),
|
|
|
|
'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
|
|
|
|
'wc-on-hold' => _x( 'On hold', 'Order status', 'woocommerce' ),
|
|
|
|
'wc-completed' => _x( 'Completed', 'Order status', 'woocommerce' ),
|
|
|
|
'wc-cancelled' => _x( 'Cancelled', 'Order status', 'woocommerce' ),
|
|
|
|
'wc-refunded' => _x( 'Refunded', 'Order status', 'woocommerce' ),
|
|
|
|
'wc-failed' => _x( 'Failed', 'Order status', 'woocommerce' ),
|
|
|
|
)
|
|
|
|
);
|
2015-03-03 11:38:05 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $order_statuses, wc_get_order_statuses() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_is_order_status().
|
2015-03-03 11:38:05 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_is_order_status() {
|
2017-01-18 17:16:01 +00:00
|
|
|
$this->assertTrue( wc_is_order_status( 'wc-pending' ) );
|
2016-12-20 22:33:35 +00:00
|
|
|
$this->assertFalse( wc_is_order_status( 'wc-another-status' ) );
|
2015-03-03 11:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_get_order_status_name().
|
2015-03-03 11:38:05 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_status_name() {
|
|
|
|
|
2016-10-12 10:16:30 +00:00
|
|
|
$this->assertEquals( _x( 'Pending payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( 'wc-pending' ) );
|
|
|
|
$this->assertEquals( _x( 'Pending payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( 'pending' ) );
|
2015-03-03 11:38:05 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 14:47:04 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_processing_order_count().
|
2017-11-24 18:57:45 +00:00
|
|
|
*
|
2015-04-14 14:47:04 +00:00
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function test_wc_processing_order_count() {
|
|
|
|
$this->assertEquals( 0, wc_processing_order_count() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_orders_count().
|
2017-11-24 18:57:45 +00:00
|
|
|
*
|
2015-04-14 14:47:04 +00:00
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function test_wc_orders_count() {
|
|
|
|
foreach ( wc_get_order_statuses() as $status ) {
|
|
|
|
$this->assertEquals( 0, wc_orders_count( $status ) );
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
// Invalid status returns 0.
|
2015-04-14 14:47:04 +00:00
|
|
|
$this->assertEquals( 0, wc_orders_count( 'unkown-status' ) );
|
|
|
|
}
|
|
|
|
|
2015-03-03 11:38:05 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_ship_to_billing_address_only().
|
2015-03-03 11:38:05 +00:00
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_ship_to_billing_address_only() {
|
|
|
|
|
|
|
|
$default = get_option( 'woocommerce_ship_to_destination' );
|
|
|
|
|
2015-03-03 11:47:13 +00:00
|
|
|
update_option( 'woocommerce_ship_to_destination', 'shipping' );
|
2016-12-20 22:33:35 +00:00
|
|
|
$this->assertFalse( wc_ship_to_billing_address_only() );
|
2015-03-03 11:38:05 +00:00
|
|
|
|
2015-03-03 11:47:13 +00:00
|
|
|
update_option( 'woocommerce_ship_to_destination', 'billing_only' );
|
2016-12-20 22:33:35 +00:00
|
|
|
$this->assertTrue( wc_ship_to_billing_address_only() );
|
2015-03-03 11:38:05 +00:00
|
|
|
|
2015-03-03 11:47:13 +00:00
|
|
|
update_option( 'woocommerce_ship_to_destination', $default );
|
2015-03-03 11:38:05 +00:00
|
|
|
}
|
2015-05-23 08:48:07 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test wc_get_order().
|
2015-05-23 08:48:07 +00:00
|
|
|
*
|
|
|
|
* @since 2.4.0
|
|
|
|
* @group test
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order() {
|
|
|
|
|
2016-03-23 12:14:13 +00:00
|
|
|
$order = WC_Helper_Order::create_order();
|
2015-05-23 08:48:07 +00:00
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
// Assert that $order is a WC_Order object.
|
2015-05-23 08:48:07 +00:00
|
|
|
$this->assertInstanceOf( 'WC_Order', $order );
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
// Assert that wc_get_order() accepts a WC_Order object.
|
2015-05-23 08:48:07 +00:00
|
|
|
$this->assertInstanceOf( 'WC_Order', wc_get_order( $order ) );
|
|
|
|
|
|
|
|
// Assert that wc_get_order() accepts a order post id.
|
2016-06-22 11:29:23 +00:00
|
|
|
$this->assertInstanceOf( 'WC_Order', wc_get_order( $order->get_id() ) );
|
2015-05-23 08:48:07 +00:00
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
// Assert that a non-shop_order post returns false.
|
2015-05-23 08:48:07 +00:00
|
|
|
$post = $this->factory->post->create_and_get( array( 'post_type' => 'post' ) );
|
|
|
|
$this->assertFalse( wc_get_order( $post->ID ) );
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
// Assert the return when $the_order args is false.
|
2015-05-23 08:48:07 +00:00
|
|
|
$this->assertFalse( wc_get_order( false ) );
|
|
|
|
|
|
|
|
// Assert the return when $the_order args is a random (incorrect) id.
|
|
|
|
$this->assertFalse( wc_get_order( 123456 ) );
|
|
|
|
}
|
2016-02-08 19:57:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getting an orders payment tokens
|
|
|
|
*
|
|
|
|
* @since 2.6
|
|
|
|
*/
|
|
|
|
public function test_wc_order_get_payment_tokens() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$order = WC_Helper_Order::create_order();
|
2016-02-08 19:57:48 +00:00
|
|
|
$this->assertEmpty( $order->get_payment_tokens() );
|
|
|
|
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = WC_Helper_Payment_Token::create_cc_token();
|
2016-06-22 11:29:23 +00:00
|
|
|
update_post_meta( $order->get_id(), '_payment_tokens', array( $token->get_id() ) );
|
2016-02-08 19:57:48 +00:00
|
|
|
|
|
|
|
$this->assertCount( 1, $order->get_payment_tokens() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test adding a payment token to an order
|
|
|
|
*
|
|
|
|
* @since 2.6
|
|
|
|
*/
|
|
|
|
public function test_wc_order_add_payment_token() {
|
2016-03-23 12:14:13 +00:00
|
|
|
$order = WC_Helper_Order::create_order();
|
2016-02-08 19:57:48 +00:00
|
|
|
$this->assertEmpty( $order->get_payment_tokens() );
|
|
|
|
|
2016-03-23 12:14:13 +00:00
|
|
|
$token = WC_Helper_Payment_Token::create_cc_token();
|
2016-02-08 19:57:48 +00:00
|
|
|
$order->add_payment_token( $token );
|
|
|
|
|
|
|
|
$this->assertCount( 1, $order->get_payment_tokens() );
|
|
|
|
}
|
2017-01-17 20:52:27 +00:00
|
|
|
|
2017-04-20 17:05:58 +00:00
|
|
|
/**
|
|
|
|
* Test the before and after date parameters for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_get_orders_customer_params() {
|
|
|
|
$order1 = WC_Helper_Order::create_order( 0 );
|
|
|
|
$order2 = WC_Helper_Order::create_order( 0 );
|
|
|
|
$order3 = WC_Helper_Order::create_order( 1 );
|
|
|
|
$order4 = WC_Helper_Order::create_order( 1 );
|
|
|
|
$order_1 = $order1->get_id();
|
|
|
|
$order_2 = $order2->get_id();
|
|
|
|
$order_3 = $order3->get_id();
|
|
|
|
$order_4 = $order4->get_id();
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'customer' => 0,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-04-20 17:05:58 +00:00
|
|
|
$expected = array( $order_1, $order_2 );
|
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'customer' => 1,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-04-20 17:05:58 +00:00
|
|
|
$expected = array( $order_3, $order_4 );
|
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'customer' => '',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-04-20 17:05:58 +00:00
|
|
|
$expected = array( $order_1, $order_2, $order_3, $order_4 );
|
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-01-17 20:52:27 +00:00
|
|
|
/**
|
2017-05-24 01:44:37 +00:00
|
|
|
* Test the legacy before and after date parameters for wc_get_orders.
|
2017-01-17 20:52:27 +00:00
|
|
|
*
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0
|
2017-01-17 20:52:27 +00:00
|
|
|
*/
|
|
|
|
public function test_wc_get_orders_date_params() {
|
2017-04-20 17:05:58 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
|
|
|
$order1->set_date_created( '2015-01-01 05:20:30' );
|
|
|
|
$order1->save();
|
|
|
|
$order_1 = $order1->get_id();
|
2018-05-08 14:55:32 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-04-20 17:05:58 +00:00
|
|
|
$order2->set_date_created( '2017-01-01' );
|
|
|
|
$order2->save();
|
|
|
|
$order_2 = $order2->get_id();
|
2018-05-08 14:55:32 +00:00
|
|
|
$order3 = WC_Helper_Order::create_order();
|
2017-04-20 17:05:58 +00:00
|
|
|
$order3->set_date_created( '2017-01-01' );
|
|
|
|
$order3->save();
|
|
|
|
$order_3 = $order3->get_id();
|
2017-01-17 20:52:27 +00:00
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'date_before' => '2017-01-15',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-01-17 20:52:27 +00:00
|
|
|
$expected = array( $order_1, $order_2, $order_3 );
|
2017-04-20 17:05:58 +00:00
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-01-17 20:52:27 +00:00
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'date_before' => '2017-01-01',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-01-17 20:52:27 +00:00
|
|
|
$expected = array( $order_1 );
|
2017-04-20 17:05:58 +00:00
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-01-17 20:52:27 +00:00
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'date_before' => '2016-12-31',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-01-17 20:52:27 +00:00
|
|
|
$expected = array( $order_1 );
|
2017-04-20 17:05:58 +00:00
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-01-17 20:52:27 +00:00
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'date_after' => '2015-01-01 00:00:00',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-01-17 20:52:27 +00:00
|
|
|
$expected = array( $order_1, $order_2, $order_3 );
|
2017-04-20 17:05:58 +00:00
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-01-17 20:52:27 +00:00
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'date_after' => '2016-01-01',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-01-17 20:52:27 +00:00
|
|
|
$expected = array( $order_2, $order_3 );
|
2017-04-20 17:05:58 +00:00
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-01-17 20:52:27 +00:00
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'date_before' => '2017-01-15',
|
2018-05-08 14:55:32 +00:00
|
|
|
'date_after' => '2015-01-01 00:00:00',
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-07-01 00:30:16 +00:00
|
|
|
$expected = array( $order_1, $order_2, $order_3 );
|
|
|
|
sort( $expected );
|
|
|
|
sort( $orders );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-01-17 20:52:27 +00:00
|
|
|
}
|
2017-05-23 13:55:28 +00:00
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the status parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_status_param() {
|
|
|
|
$order1 = WC_Helper_Order::create_order();
|
|
|
|
$order1->set_status( 'pending' );
|
|
|
|
$order1->save();
|
|
|
|
$order2 = WC_Helper_Order::create_order();
|
|
|
|
$order2->set_status( 'completed' );
|
|
|
|
$order2->save();
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'status' => 'pending',
|
|
|
|
'return' => 'ids',
|
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'status' => 'completed',
|
|
|
|
'return' => 'ids',
|
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the type parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_type_param() {
|
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
$order->save();
|
|
|
|
$refund = new WC_Order_Refund();
|
|
|
|
$refund->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'type' => 'shop_order_refund',
|
2017-11-24 18:57:45 +00:00
|
|
|
'return' => 'ids',
|
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $refund->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'type' => 'shop_order',
|
2017-11-24 18:57:45 +00:00
|
|
|
'return' => 'ids',
|
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the version parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_version_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'version' => WC_VERSION,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-05-24 01:44:37 +00:00
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'version' => '2.1.0',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array();
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-05-23 13:55:28 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the created_via parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_created_via_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->set_created_via( 'rest-api' );
|
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->set_created_via( 'checkout' );
|
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'created_via' => 'rest-api',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'created_via' => 'checkout',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the parent parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_parent_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$parent = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$parent->save();
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->set_parent_id( $parent->get_id() );
|
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'parent' => $parent->get_id(),
|
|
|
|
'return' => 'ids',
|
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the parent_exclude parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_parent_exclude_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$parent = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$parent->save();
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->set_parent_id( $parent->get_id() );
|
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->save();
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'parent_exclude' => array( $parent->get_id() ),
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
sort( $orders );
|
|
|
|
$expected = array( $parent->get_id(), $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the exclude parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_exclude_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'exclude' => array( $order1->get_id() ),
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the limit parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_limit_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->save();
|
|
|
|
|
|
|
|
$orders = wc_get_orders( array( 'limit' => 1 ) );
|
|
|
|
$this->assertEquals( 1, count( $orders ) );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the paged parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_paged_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'paged' => 1,
|
2017-11-24 18:57:45 +00:00
|
|
|
'orderby' => 'ID',
|
2018-05-08 14:55:32 +00:00
|
|
|
'order' => 'ASC',
|
|
|
|
'limit' => 1,
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'paged' => 2,
|
2017-11-24 18:57:45 +00:00
|
|
|
'orderby' => 'ID',
|
2018-05-08 14:55:32 +00:00
|
|
|
'order' => 'ASC',
|
|
|
|
'limit' => 1,
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the offset parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_offset_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'offset' => 1,
|
2017-11-24 18:57:45 +00:00
|
|
|
'orderby' => 'ID',
|
2018-05-08 14:55:32 +00:00
|
|
|
'order' => 'ASC',
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the paginate parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_paginate_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->save();
|
|
|
|
|
|
|
|
$orders = wc_get_orders( array( 'paginate' => true ) );
|
|
|
|
$this->assertEquals( 2, $orders->total );
|
|
|
|
$this->assertEquals( 2, count( $orders->orders ) );
|
2017-06-12 20:26:29 +00:00
|
|
|
$this->assertInstanceOf( 'WC_Order', $orders->orders[0] );
|
2017-05-23 13:55:28 +00:00
|
|
|
$this->assertEquals( 1, $orders->max_num_pages );
|
|
|
|
}
|
|
|
|
|
2017-06-12 20:26:29 +00:00
|
|
|
/**
|
|
|
|
* Test the paginate parameter with return id for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_paginate_id_param() {
|
|
|
|
$order = WC_Helper_order::create_order();
|
|
|
|
$order->save();
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$orders = wc_get_orders(
|
|
|
|
array(
|
|
|
|
'paginate' => true,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-06-12 20:26:29 +00:00
|
|
|
$this->assertEquals( 1, $orders->total );
|
|
|
|
$this->assertEquals( 1, $orders->max_num_pages );
|
|
|
|
$this->assertEquals( $order->get_id(), $orders->orders[0] );
|
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the order parameters for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_order_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'orderby' => 'ID',
|
2018-05-08 14:55:32 +00:00
|
|
|
'order' => 'DESC',
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order2->get_id(), $order1->get_id() );
|
2017-05-24 01:44:37 +00:00
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-05-23 13:55:28 +00:00
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'orderby' => 'ID',
|
2018-05-08 14:55:32 +00:00
|
|
|
'order' => 'ASC',
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order1->get_id(), $order2->get_id() );
|
2017-05-24 01:44:37 +00:00
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-05-23 13:55:28 +00:00
|
|
|
}
|
|
|
|
|
2017-05-24 01:44:37 +00:00
|
|
|
/**
|
|
|
|
* Test the currency parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
2017-05-23 13:55:28 +00:00
|
|
|
public function test_wc_get_order_currency_param() {
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order1->set_currency( 'BRL' );
|
|
|
|
$order1->save();
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-05-23 13:55:28 +00:00
|
|
|
$order2->set_currency( 'USD' );
|
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'currency' => 'BRL',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
2017-05-24 01:44:37 +00:00
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-05-23 13:55:28 +00:00
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'currency' => 'USD',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-23 13:55:28 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
2017-05-24 01:44:37 +00:00
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the prices_include_tax parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_prices_include_tax_param() {
|
|
|
|
$order1 = WC_Helper_Order::create_order();
|
|
|
|
$order1->set_prices_include_tax( true );
|
|
|
|
$order1->save();
|
|
|
|
$order2 = WC_Helper_Order::create_order();
|
|
|
|
$order2->set_prices_include_tax( false );
|
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'prices_include_tax' => 'yes',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'prices_include_tax' => 'no',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the payment_method parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_payment_method_param() {
|
|
|
|
$order1 = WC_Helper_Order::create_order();
|
|
|
|
$order1->set_payment_method( 'cheque' );
|
|
|
|
$order1->save();
|
|
|
|
$order2 = WC_Helper_Order::create_order();
|
|
|
|
$order2->set_payment_method( 'cod' );
|
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'payment_method' => 'cheque',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'payment_method' => 'cod',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the payment_method_title parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
|
|
|
public function test_get_order_payment_method_title_param() {
|
|
|
|
$order1 = WC_Helper_Order::create_order();
|
|
|
|
$order1->set_payment_method_title( 'Check payments' );
|
|
|
|
$order1->save();
|
|
|
|
$order2 = WC_Helper_Order::create_order();
|
|
|
|
$order2->set_payment_method_title( 'PayPal' );
|
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'payment_method_title' => 'Check payments',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'payment_method_title' => 'PayPal',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the price parameters for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_price_price_params() {
|
|
|
|
$order1 = new WC_Order();
|
|
|
|
$order1->set_discount_total( 5.50 );
|
|
|
|
$order1->set_discount_tax( 0.50 );
|
|
|
|
$order1->set_shipping_total( 3.99 );
|
2017-07-06 18:12:02 +00:00
|
|
|
$order1->set_shipping_tax( 0.25 );
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1->set_cart_tax( 0.10 );
|
|
|
|
$order1->set_total( 10.34 );
|
|
|
|
$order1->save();
|
|
|
|
$order2 = new WC_Order();
|
|
|
|
$order2->set_discount_total( 2.50 );
|
|
|
|
$order2->set_discount_tax( 0.20 );
|
|
|
|
$order2->set_shipping_total( 2.99 );
|
2017-07-06 18:12:02 +00:00
|
|
|
$order2->set_shipping_tax( 0.15 );
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2->set_cart_tax( 0.05 );
|
|
|
|
$order2->set_total( 5.89 );
|
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'discount_total' => 5.50,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'discount_tax' => 0.20,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_total' => 3.99,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_tax' => 0.15,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'cart_tax' => 0.10,
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'total' => 5.89,
|
2017-11-24 18:57:45 +00:00
|
|
|
'return' => 'ids',
|
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the customer parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_customer_param() {
|
|
|
|
$customer1 = WC_Helper_Customer::create_customer( 'customer1', 'password', 'test1@test.com' );
|
|
|
|
$customer1->set_billing_email( 'customer1@test.com' );
|
|
|
|
$customer1->save();
|
|
|
|
|
|
|
|
$customer2 = WC_Helper_Customer::create_customer( 'customer2', 'password', 'test2@test.com' );
|
|
|
|
$customer2->set_billing_email( 'customer2@test.com' );
|
|
|
|
$customer2->save();
|
|
|
|
|
|
|
|
$order1 = WC_Helper_Order::create_order();
|
|
|
|
$order1->set_customer_id( $customer1->get_id() );
|
|
|
|
$order1->set_billing_email( $customer1->get_billing_email() );
|
|
|
|
$order1->save();
|
|
|
|
$order2 = WC_Helper_Order::create_order();
|
|
|
|
$order2->set_customer_id( $customer2->get_id() );
|
|
|
|
$order2->set_billing_email( $customer2->get_billing_email() );
|
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'customer' => $customer1->get_billing_email(),
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'customer' => $customer2->get_id(),
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-06-13 20:32:21 +00:00
|
|
|
|
|
|
|
$orders = wc_get_orders( array( 'customer' => 'invalid' ) );
|
|
|
|
$this->assertEmpty( $orders );
|
|
|
|
|
|
|
|
$orders = wc_get_orders( array( 'customer' => array( 'invalid' ) ) );
|
|
|
|
$this->assertEmpty( $orders );
|
|
|
|
|
2017-06-13 21:00:12 +00:00
|
|
|
$orders = wc_get_orders( array( 'customer' => array( '' ) ) );
|
|
|
|
$this->assertEmpty( $orders );
|
|
|
|
|
2017-06-13 20:32:21 +00:00
|
|
|
$orders = wc_get_orders( array( 'customer' => 'doesnt@exist.com' ) );
|
|
|
|
$this->assertEmpty( $orders );
|
2017-05-24 01:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the customer_id parameter for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_customer_id_param() {
|
|
|
|
$customer1 = WC_Helper_Customer::create_customer( 'customer1', 'password', 'test1@test.com' );
|
|
|
|
$customer1->set_billing_email( 'customer1@test.com' );
|
|
|
|
$customer1->save();
|
|
|
|
|
|
|
|
$customer2 = WC_Helper_Customer::create_customer( 'customer2', 'password', 'test2@test.com' );
|
|
|
|
$customer2->set_billing_email( 'customer2@test.com' );
|
|
|
|
$customer2->save();
|
|
|
|
|
|
|
|
$order1 = WC_Helper_Order::create_order();
|
|
|
|
$order1->set_customer_id( $customer1->get_id() );
|
|
|
|
$order1->save();
|
|
|
|
$order2 = WC_Helper_Order::create_order();
|
|
|
|
$order2->set_customer_id( $customer2->get_id() );
|
|
|
|
$order2->save();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'customer_id' => $customer1->get_id(),
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'customer_id' => $customer2->get_id(),
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the address parameters for wc_get_orders.
|
|
|
|
*
|
|
|
|
* @since 3.1
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_address_params() {
|
|
|
|
$order1 = WC_Helper_Order::create_order();
|
2017-11-24 18:57:45 +00:00
|
|
|
$order1->set_props(
|
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'billing_email' => 'test1@test.com',
|
|
|
|
'billing_first_name' => 'Bill',
|
|
|
|
'billing_last_name' => 'Powers',
|
|
|
|
'billing_company' => 'TestCo.',
|
|
|
|
'billing_address_1' => '1234 Cool St.',
|
|
|
|
'billing_address_2' => 'Apt 2',
|
|
|
|
'billing_city' => 'Portland',
|
|
|
|
'billing_state' => 'OR',
|
|
|
|
'billing_postcode' => '97266',
|
2018-05-24 20:49:54 +00:00
|
|
|
'billing_country' => 'US',
|
2018-05-08 14:55:32 +00:00
|
|
|
'billing_phone' => '503-123-4567',
|
2017-11-24 18:57:45 +00:00
|
|
|
'shipping_first_name' => 'Jane',
|
2018-05-08 14:55:32 +00:00
|
|
|
'shipping_last_name' => 'Powers',
|
|
|
|
'shipping_company' => '',
|
|
|
|
'shipping_address_1' => '4321 Cool St.',
|
|
|
|
'shipping_address_2' => 'Apt 1',
|
|
|
|
'shipping_city' => 'Milwaukie',
|
|
|
|
'shipping_state' => 'OR',
|
|
|
|
'shipping_postcode' => '97222',
|
2018-05-24 20:49:54 +00:00
|
|
|
'shipping_country' => 'US',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$order1->save();
|
|
|
|
$order1_id = $order1->get_id();
|
|
|
|
|
|
|
|
$order2 = WC_Helper_Order::create_order();
|
2017-11-24 18:57:45 +00:00
|
|
|
$order2->set_props(
|
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'billing_email' => 'test2@test.com',
|
|
|
|
'billing_first_name' => 'Joe',
|
|
|
|
'billing_last_name' => 'Thunder',
|
|
|
|
'billing_company' => 'ThunderCo.',
|
|
|
|
'billing_address_1' => '1234 Thunder St.',
|
|
|
|
'billing_address_2' => '',
|
|
|
|
'billing_city' => 'Vancouver',
|
|
|
|
'billing_state' => 'WA',
|
|
|
|
'billing_postcode' => '97267',
|
2018-05-24 20:49:54 +00:00
|
|
|
'billing_country' => 'US',
|
2018-05-08 14:55:32 +00:00
|
|
|
'billing_phone' => '503-333-3333',
|
2017-11-24 18:57:45 +00:00
|
|
|
'shipping_first_name' => 'Joseph',
|
2018-05-08 14:55:32 +00:00
|
|
|
'shipping_last_name' => 'Thunder',
|
|
|
|
'shipping_company' => 'Thunder Inc',
|
|
|
|
'shipping_address_1' => '1 Thunder Blvd',
|
|
|
|
'shipping_address_2' => '',
|
|
|
|
'shipping_city' => 'Vancouver',
|
|
|
|
'shipping_state' => 'WA',
|
|
|
|
'shipping_postcode' => '97233',
|
2018-05-24 20:49:54 +00:00
|
|
|
'shipping_country' => 'US',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$order2->save();
|
|
|
|
$order2_id = $order2->get_id();
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_email' => 'test1@test.com',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_first_name' => 'Joe',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_last_name' => 'Powers',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_company' => 'ThunderCo.',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_address_1' => '1234 Cool St.',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_address_2' => 'Apt 2',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_city' => 'Vancouver',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_state' => 'OR',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_postcode' => '97267',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
2018-05-24 20:49:54 +00:00
|
|
|
'billing_country' => 'US',
|
2018-05-08 14:55:32 +00:00
|
|
|
'orderby' => 'ID',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id, $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_phone' => '503-333-3333',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_first_name' => 'Jane',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_last_name' => 'Thunder',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_company' => 'Thunder Inc',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_address_1' => '1 Thunder Blvd',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_address_2' => 'Apt 1',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_city' => 'Vancouver',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_state' => 'OR',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'shipping_postcode' => '97233',
|
2018-05-08 14:55:32 +00:00
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
2018-05-24 20:49:54 +00:00
|
|
|
'shipping_country' => 'US',
|
2018-05-08 14:55:32 +00:00
|
|
|
'orderby' => 'ID',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order1_id, $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders(
|
2017-11-24 18:57:45 +00:00
|
|
|
array(
|
|
|
|
'billing_first_name' => 'Joe',
|
2018-05-08 14:55:32 +00:00
|
|
|
'billing_last_name' => 'Thunder',
|
|
|
|
'return' => 'ids',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-05-24 01:44:37 +00:00
|
|
|
$expected = array( $order2_id );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
2017-05-23 13:55:28 +00:00
|
|
|
}
|
2017-07-12 21:46:52 +00:00
|
|
|
|
2017-10-24 20:07:21 +00:00
|
|
|
/**
|
|
|
|
* Test wc_get_order date queries combined with meta queries.
|
|
|
|
*
|
|
|
|
* @since 3.2
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_mixed_date_shipping_country() {
|
|
|
|
// Set up dates.
|
2018-05-08 14:55:32 +00:00
|
|
|
$start = time() - 1; // Start from one second ago.
|
|
|
|
$yesterday = strtotime( '-1 day', $start );
|
|
|
|
$end = strtotime( '+1 day', $start );
|
2017-10-24 20:07:21 +00:00
|
|
|
$date_range = $start . '...' . $end;
|
|
|
|
|
|
|
|
// Populate orders.
|
|
|
|
$us_now = WC_Helper_Order::create_order();
|
2017-11-24 18:57:45 +00:00
|
|
|
$us_now->set_props(
|
|
|
|
array(
|
|
|
|
'shipping_country' => 'US',
|
|
|
|
)
|
|
|
|
);
|
2017-10-24 20:07:21 +00:00
|
|
|
$us_now->save();
|
|
|
|
|
|
|
|
$us_old = WC_Helper_Order::create_order();
|
2017-11-24 18:57:45 +00:00
|
|
|
$us_old->set_props(
|
|
|
|
array(
|
2018-05-08 14:55:32 +00:00
|
|
|
'date_created' => $yesterday,
|
2017-11-24 18:57:45 +00:00
|
|
|
'shipping_country' => 'US',
|
|
|
|
)
|
|
|
|
);
|
2017-10-24 20:07:21 +00:00
|
|
|
$us_old->save();
|
|
|
|
|
|
|
|
$mx_now = WC_Helper_Order::create_order();
|
2017-11-24 18:57:45 +00:00
|
|
|
$mx_now->set_props(
|
|
|
|
array(
|
|
|
|
'shipping_country' => 'MX',
|
|
|
|
)
|
|
|
|
);
|
2017-10-24 20:07:21 +00:00
|
|
|
$mx_now->save();
|
|
|
|
|
|
|
|
$mx_old = WC_Helper_Order::create_order();
|
2017-11-24 18:57:45 +00:00
|
|
|
$mx_old->set_props(
|
|
|
|
array(
|
|
|
|
'date_created' => $yesterday,
|
|
|
|
'shipping_country' => 'MX',
|
|
|
|
)
|
|
|
|
);
|
2017-10-24 20:07:21 +00:00
|
|
|
$mx_old->save();
|
|
|
|
|
|
|
|
// Test just date range.
|
2018-05-08 14:55:32 +00:00
|
|
|
$args = array(
|
2017-10-24 20:07:21 +00:00
|
|
|
'return' => 'ids',
|
|
|
|
'date_created' => $date_range,
|
|
|
|
'orderby' => 'ID',
|
|
|
|
'order' => 'ASC',
|
|
|
|
);
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders( $args );
|
2017-10-24 20:07:21 +00:00
|
|
|
$expected = array( $us_now->get_id(), $mx_now->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
|
|
|
// Test just US orders.
|
2018-05-08 14:55:32 +00:00
|
|
|
$args = array(
|
2017-10-24 20:07:21 +00:00
|
|
|
'return' => 'ids',
|
|
|
|
'shipping_country' => 'US',
|
|
|
|
'orderby' => 'ID',
|
|
|
|
'order' => 'ASC',
|
|
|
|
);
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders( $args );
|
2017-10-24 20:07:21 +00:00
|
|
|
$expected = array( $us_now->get_id(), $us_old->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
|
|
|
|
// Test US orders with date range.
|
2018-05-08 14:55:32 +00:00
|
|
|
$args = array(
|
2017-10-24 20:07:21 +00:00
|
|
|
'return' => 'ids',
|
|
|
|
'date_created' => $date_range,
|
|
|
|
'shipping_country' => 'US',
|
|
|
|
'orderby' => 'ID',
|
|
|
|
'order' => 'ASC',
|
|
|
|
);
|
2018-05-08 14:55:32 +00:00
|
|
|
$orders = wc_get_orders( $args );
|
2017-10-24 20:07:21 +00:00
|
|
|
$expected = array( $us_now->get_id() );
|
|
|
|
$this->assertEquals( $expected, $orders );
|
|
|
|
}
|
|
|
|
|
2017-07-12 21:46:52 +00:00
|
|
|
/**
|
|
|
|
* Test wc_get_order_note().
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_note() {
|
|
|
|
$note_content = 'Note content';
|
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
$note_id = (int) $order->add_order_note( $note_content );
|
|
|
|
$expected = array(
|
|
|
|
'id' => $note_id,
|
2017-07-13 22:30:25 +00:00
|
|
|
'content' => $note_content,
|
2017-07-12 21:46:52 +00:00
|
|
|
'customer_note' => false,
|
|
|
|
'added_by' => 'system',
|
|
|
|
);
|
2018-05-08 14:55:32 +00:00
|
|
|
$note = (array) wc_get_order_note( $note_id );
|
2017-07-12 21:46:52 +00:00
|
|
|
unset( $note['date_created'] );
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $note );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_get_order_notes().
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function test_wc_get_order_notes() {
|
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
$order->add_order_note( 'Customer note', 1 );
|
|
|
|
$order->add_order_note( 'Internal note' );
|
|
|
|
$order->add_order_note( 'Another internal note' );
|
|
|
|
|
|
|
|
$notes = wc_get_order_notes( array( 'order_id' => $order->get_id() ) );
|
|
|
|
$this->assertEquals( 3, count( $notes ) );
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$notes = wc_get_order_notes(
|
|
|
|
array(
|
|
|
|
'order_id' => $order->get_id(),
|
2018-05-08 14:55:32 +00:00
|
|
|
'type' => 'customer',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-07-12 21:46:52 +00:00
|
|
|
$this->assertEquals( 1, count( $notes ) );
|
|
|
|
|
2017-11-24 18:57:45 +00:00
|
|
|
$notes = wc_get_order_notes(
|
|
|
|
array(
|
|
|
|
'order_id' => $order->get_id(),
|
2018-05-08 14:55:32 +00:00
|
|
|
'type' => 'internal',
|
2017-11-24 18:57:45 +00:00
|
|
|
)
|
|
|
|
);
|
2017-07-12 21:46:52 +00:00
|
|
|
$this->assertEquals( 2, count( $notes ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_create_order_note().
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function test_wc_create_order_note() {
|
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
|
|
|
|
$note_id = wc_create_order_note( $order->get_id(), 'Note content', false, false );
|
|
|
|
$this->assertTrue( 0 < $note_id );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_delete_order_note().
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function test_wc_delete_order_note() {
|
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
$note_id = $order->add_order_note( 'Note content' );
|
|
|
|
|
|
|
|
$this->assertTrue( wc_delete_order_note( $note_id ) );
|
|
|
|
}
|
2017-11-24 19:04:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_order_search()
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
public function test_wc_order_search() {
|
|
|
|
$order = WC_Helper_Order::create_order();
|
|
|
|
|
|
|
|
// Should find order searching by billing address name.
|
|
|
|
$this->assertEquals( array( $order->get_id() ), wc_order_search( 'Jeroen' ) );
|
|
|
|
|
|
|
|
// Should find order searching by order item name.
|
|
|
|
$this->assertEquals( array( $order->get_id() ), wc_order_search( 'Dummy Product' ) );
|
|
|
|
|
|
|
|
// Should return nothing when searching for nonexistent term.
|
|
|
|
$this->assertEmpty( wc_order_search( 'Nonexistent term' ) );
|
|
|
|
}
|
2015-03-03 11:38:05 +00:00
|
|
|
}
|