Remove query for products type in Shipping Task (#33886)
This commit is contained in:
parent
5093710ad4
commit
a7d34b22aa
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: performance
|
||||
|
||||
Improve performance of Shipping Task.
|
|
@ -174,15 +174,7 @@ class Shipping extends Task {
|
|||
$profiler_data = get_option( OnboardingProfile::DATA_OPTION, array() );
|
||||
$product_types = isset( $profiler_data['product_types'] ) ? $profiler_data['product_types'] : array();
|
||||
|
||||
return in_array( 'physical', $product_types, true ) ||
|
||||
count(
|
||||
wc_get_products(
|
||||
array(
|
||||
'virtual' => false,
|
||||
'limit' => 1,
|
||||
)
|
||||
)
|
||||
) > 0;
|
||||
return in_array( 'physical', $product_types, true );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,6 +61,37 @@ class WC_Admin_Tests_OnboardingTasks_Task_Shipping extends WC_Unit_Test_Case {
|
|||
return array_merge( $features, array( 'shipping-smart-defaults' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test can_view function of task when store only sells physical products.
|
||||
*/
|
||||
public function test_can_view_return_true_when_sell_only_physical_type() {
|
||||
update_option(
|
||||
OnboardingProfile::DATA_OPTION,
|
||||
array(
|
||||
'product_types' => array(
|
||||
'physical',
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEquals( $this->task->can_view(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test can_view function of task when store sells physical and digital products.
|
||||
*/
|
||||
public function test_can_view_return_true_when_sell_physical_and_digital_type() {
|
||||
update_option(
|
||||
OnboardingProfile::DATA_OPTION,
|
||||
array(
|
||||
'product_types' => array(
|
||||
'physical',
|
||||
'digital',
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->assertEquals( $this->task->can_view(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test can_view function of task when store only sells digital products.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue