Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks
Product_Collection::get_sample_product_ids_for_preview
Get sample product IDs for preview emails. This ensures that preview emails show representative content even when the cart is empty.
Method of the class: Product_Collection{}
No Hooks.
Returns
Array. Array of sample product IDs.
Usage
// private - for code of main (parent) class only $result = $this->get_sample_product_ids_for_preview(): array;
Product_Collection::get_sample_product_ids_for_preview() Product Collection::get sample product ids for preview code WC 10.8.1
private function get_sample_product_ids_for_preview(): array {
$query = new WP_Query(
array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
)
);
if ( ! empty( $query->posts ) && is_array( $query->posts ) ) {
return array_map(
static function ( $id ) {
return is_numeric( $id ) ? (int) $id : 0;
},
$query->posts
);
}
return array( -1 );
}