Updated High Performance Order Storage Upgrade Recipe Book (markdown)
parent
b80d4d34f4
commit
f6555c314a
|
@ -77,7 +77,7 @@ To help with this, we have provided a few guidelines for extension developers to
|
||||||
While the WooCommerce CRUD API will let you support both posts and custom tables without additional effort most of the time, in some cases (like when you are writing a SQL query for better performance) you would want to know whether the store is using HPOS tables or not. In this case, you can use the following pattern:
|
While the WooCommerce CRUD API will let you support both posts and custom tables without additional effort most of the time, in some cases (like when you are writing a SQL query for better performance) you would want to know whether the store is using HPOS tables or not. In this case, you can use the following pattern:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Automattic\WooCommerce\Utilities\woocommerce;
|
use Automattic\WooCommerce\Utilities\OrderUtil;
|
||||||
|
|
||||||
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
|
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
|
||||||
// HPOS usage is enabled.
|
// HPOS usage is enabled.
|
||||||
|
@ -135,12 +135,12 @@ When getting exact type of an order, or checking if given ID is an order, you ca
|
||||||
|
|
||||||
```php
|
```php
|
||||||
// Pattern to check when an ID is an order
|
// Pattern to check when an ID is an order
|
||||||
‘shop_order’ === get_post_type( $post_id ); // or
|
'shop_order' === get_post_type( $post_id ); // or
|
||||||
in_array( get_post_type( $post_type ), wc_get_order_types() );
|
in_array( get_post_type( $post_type ), wc_get_order_types() );
|
||||||
|
|
||||||
// replace with:
|
// replace with:
|
||||||
use Automattic\WooCommerce\Utilities\OrderUtil;
|
use Automattic\WooCommerce\Utilities\OrderUtil;
|
||||||
‘shop_order’ === OrderUtil::get_order_type( $post_id ); // or
|
'shop_order' === OrderUtil::get_order_type( $post_id ); // or
|
||||||
OrderUtil::is_order( $post_id, wc_get_order_types() );
|
OrderUtil::is_order( $post_id, wc_get_order_types() );
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -200,8 +200,10 @@ Once you examined the extension's code, you can declare whether it's compatible
|
||||||
use Automattic\WooCommerce\Internal\Features\FeaturesController;
|
use Automattic\WooCommerce\Internal\Features\FeaturesController;
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'init',
|
'init',
|
||||||
FeaturesController::declare_compatibility( 'custom_order_tables', basename(__DIR__) )
|
function() {
|
||||||
|
FeaturesController::declare_compatibility( 'custom_order_tables', basename(__DIR__) );
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -212,8 +214,10 @@ If you know your code doesn't support HPOS, you should declare incompatibility i
|
||||||
use Automattic\WooCommerce\Internal\Features\FeaturesController;
|
use Automattic\WooCommerce\Internal\Features\FeaturesController;
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'init',
|
'init',
|
||||||
FeaturesController::declare_compatibility( 'custom_order_tables', basename(__DIR__), false )
|
function() {
|
||||||
|
FeaturesController::declare_compatibility( 'custom_order_tables', basename(__DIR__), false );
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue