Automattic\WooCommerce\Blocks\AIContent
UpdateProducts::fetch_dummy_products_to_update()
Return all dummy products that were not modified by the store owner.
Метод класса: UpdateProducts{}
Хуков нет.
Возвращает
Массив|WP_Error
. An array with the dummy products that need to have their content updated by AI.
Использование
$UpdateProducts = new UpdateProducts(); $UpdateProducts->fetch_dummy_products_to_update();
Код UpdateProducts::fetch_dummy_products_to_update() UpdateProducts::fetch dummy products to update WC 9.5.1
public function fetch_dummy_products_to_update() { $real_products = $this->fetch_product_ids(); $real_products_count = count( $real_products ); if ( is_array( $real_products ) && $real_products_count > 6 ) { return array( 'product_content' => array(), ); } $dummy_products = $this->fetch_product_ids( 'dummy' ); $dummy_products_count = count( $dummy_products ); $products_to_create = max( 0, 6 - $real_products_count - $dummy_products_count ); while ( $products_to_create > 0 ) { $this->create_new_product( self::DUMMY_PRODUCTS[ $products_to_create - 1 ] ); --$products_to_create; } // Identify dummy products that need to have their content updated. $dummy_products_ids = $this->fetch_product_ids( 'dummy' ); if ( ! is_array( $dummy_products_ids ) ) { return new \WP_Error( 'failed_to_fetch_dummy_products', __( 'Failed to fetch dummy products.', 'woocommerce' ) ); } $dummy_products = array_map( function ( $product ) { return wc_get_product( $product->ID ); }, $dummy_products_ids ); $dummy_products_to_update = []; foreach ( $dummy_products as $dummy_product ) { if ( ! $dummy_product instanceof \WC_Product ) { continue; } $should_update_dummy_product = $this->should_update_dummy_product( $dummy_product ); if ( $should_update_dummy_product ) { $dummy_products_to_update[] = $dummy_product; } } return $dummy_products_to_update; }