); add_action( 'before_delete_post', $pre_delete, 90 ); add_action( 'woocommerce_before_delete_product_variation', $pre_delete, 90 ); add_action( 'trashed_post', $delete, 90 ); add_action( 'deleted_post', $delete, 90 ); add_action( 'woocommerce_delete_product_variation', $delete, 90 ); add_action( 'woocommerce_trash_product_variation', $delete, 90 ); // when a product is restored from the trash, schedule an "update" job. add_action( 'untrashed_post', $update_by_id, 90 ); // exclude the sync metadata when duplicating the product add_action( 'woocommerce_duplicate_product_exclude_meta', function ( array $exclude_meta ) { return $this->get_duplicated_product_excluded_meta( $exclude_meta ); }, 90 ); } /** * Handle updating of a product. * * @param WC_Product[] $products The products being saved. * * @return void */ protected function handle_update_products( array $products ) { $products_to_update = []; $products_to_delete = []; foreach ( $products as $product ) { $product_id = $product->get_id(); // Bail if an event is already scheduled for this product in the current request if ( $this->is_already_scheduled_to_update( $product_id ) ) { continue; } // If it's a variable product we handle each variation separately if ( $product instanceof WC_Product_Variable ) { $this->handle_update_products( $product->get_available_variations( 'objects' ) ); continue; } // Schedule an update job if product sync is enabled. if ( $this->product_helper->is_sync_ready( $product ) ) { $this->product_helper->mark_as_pending( $product ); $products_to_update[] = $product->get_id(); $this->set_already_scheduled_to_update( $product_id ); } elseif ( $this->product_helper->is_product_synced( $product ) ) { // Delete the product from Google Merchant Center if it's already synced BUT it is not sync ready after the edit. $products_to_delete[] = $product; $this->set_already_scheduled_to_delete( $product_id ); do_action( 'woocommerce_gla_debug_message', sprintf( 'Deleting product (ID: %s) from Google Merchant Center because it is not ready to be synced.', $product->get_id() ), __METHOD__ ); } else { $this->product_helper->mark_as_unsynced( $product ); } } if ( ! empty( $products_to_update ) ) { $this->update_products_job->schedule( [ $products_to_update ] ); } if ( ! empty( $products_to_delete ) ) { $request_entries = $this->batch_helper->generate_delete_request_entries( $products_to_delete ); $this->delete_products_job->schedule( [ BatchProductIDRequestEntry::convert_to_id_map( $request_entries )->get() ] ); } } /** * Handle deleting of a product. * * @param int $product_id */ protected function handle_delete_product( int $product_id ) { if ( isset( $this->delete_requests_map[ $product_id ] ) ) { $product_id_map = BatchProductIDRequestEntry::convert_to_id_map( $this->delete_requests_map[ $product_id ] )->get(); if ( ! empty( $product_id_map ) && ! $this->is_already_scheduled_to_delete( $product_id ) ) { $this->delete_products_job->schedule( [ $product_id_map ] ); $this->set_already_scheduled_to_delete( $product_id ); } } } /** * Create request entries for the product (containing its Google ID) so that we can schedule a delete job when the * product is actually trashed / deleted. * * @param int $product_id */ protected function handle_pre_delete_product( int $product_id ) { $product = $this->wc->maybe_get_product( $product_id ); // each variation is passed to this method separately so we don't need to delete the variable product if ( $product instanceof WC_Product && ! $product instanceof WC_Product_Variable && $this->product_helper->is_product_synced( $product ) ) { $this->delete_requests_map[ $product_id ] = $this->batch_helper->generate_delete_request_entries( [ $product ] ); } } /** * Return the list of metadata keys to be excluded when duplicating a product. * * @param array $exclude_meta The keys to exclude from the duplicate. * * @return array */ protected function get_duplicated_product_excluded_meta( array $exclude_meta ): array { $exclude_meta[] = $this->prefix_meta_key( ProductMetaHandler::KEY_SYNCED_AT ); $exclude_meta[] = $this->prefix_meta_key( ProductMetaHandler::KEY_GOOGLE_IDS ); $exclude_meta[] = $this->prefix_meta_key( ProductMetaHandler::KEY_ERRORS ); $exclude_meta[] = $this->prefix_meta_key( ProductMetaHandler::KEY_FAILED_SYNC_ATTEMPTS ); $exclude_meta[] = $this->prefix_meta_key( ProductMetaHandler::KEY_SYNC_FAILED_AT ); $exclude_meta[] = $this->prefix_meta_key( ProductMetaHandler::KEY_SYNC_STATUS ); $exclude_meta[] = $this->prefix_meta_key( ProductMetaHandler::KEY_MC_STATUS ); return $exclude_meta; } /** * @param int $product_id * @param string $schedule_type * * @return bool */ protected function is_already_scheduled( int $product_id, string $schedule_type ): bool { return isset( $this->already_scheduled[ $product_id ] ) && $this->already_scheduled[ $product_id ] === $schedule_type; } /** * @param int $product_id * * @return bool */ protected function is_already_scheduled_to_update( int $product_id ): bool { return $this->is_already_scheduled( $product_id, self::SCHEDULE_TYPE_UPDATE ); } /** * @param int $product_id * * @return bool */ protected function is_already_scheduled_to_delete( int $product_id ): bool { return $this->is_already_scheduled( $product_id, self::SCHEDULE_TYPE_DELETE ); } /** * @param int $product_id * @param string $schedule_type * * @return void */ protected function set_already_scheduled( int $product_id, string $schedule_type ): void { $this->already_scheduled[ $product_id ] = $schedule_type; } /** * @param int $product_id * * @return void */ protected function set_already_scheduled_to_update( int $product_id ): void { $this->set_already_scheduled( $product_id, self::SCHEDULE_TYPE_UPDATE ); } /** * @param int $product_id * * @return void */ protected function set_already_scheduled_to_delete( int $product_id ): void { $this->set_already_scheduled( $product_id, self::SCHEDULE_TYPE_DELETE ); } }
Warning: class_implements(): Class Automattic\WooCommerce\GoogleListingsAndAds\Product\SyncerHooks does not exist and could not be loaded in /htdocs/wp-content/plugins/google-listings-and-ads/src/Internal/DependencyManagement/AbstractServiceProvider.php on line 73

Warning: foreach() argument must be of type array|object, bool given in /htdocs/wp-content/plugins/google-listings-and-ads/src/Internal/DependencyManagement/AbstractServiceProvider.php on line 73
SOUTRAMALL - SOUTRAMARKET