$productId, 'field' => $field, ); self::save( $state ); } /** * Records a field that could not be written for a reason other than the * three-way rule's conflict outcome (invalid JSON, no SEO plugin, an * unknown attachment id, and so on). * * @param int $productId Product id. * @param string $field Column id or canonical field name. * @param string $reason Short machine-readable reason code. * @return void */ public static function addSkipped( int $productId, string $field, string $reason ): void { $state = self::state(); $state['skipped'][] = array( 'productId' => $productId, 'field' => $field, 'reason' => $reason, ); self::save( $state ); } /** * Echoes, then deletes, the current user's report notice when there is * something to report. * * @return void */ public static function renderNotice(): void { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $key = self::transientKey(); $state = get_transient( $key ); if ( ! is_array( $state ) ) { return; } $written = (int) ( $state['written_fields'] ?? 0 ); $conflicts = is_array( $state['conflicts'] ?? null ) ? count( $state['conflicts'] ) : 0; if ( $written <= 0 && $conflicts <= 0 ) { delete_transient( $key ); return; } $sentences = array(); if ( $written > 0 ) { $sentences[] = sprintf( /* translators: %d: number of fields updated from the CSV. */ _n( 'AI Product Tools updated %d field from the CSV.', 'AI Product Tools updated %d fields from the CSV.', $written, 'ai-product-tools' ), $written ); } if ( $conflicts > 0 ) { $sentences[] = sprintf( /* translators: %d: number of fields left unchanged because of a store-side edit since export. */ _n( '%d was left as it is because it changed in the store after the export.', '%d were left as they are because they changed in the store after the export.', $conflicts, 'ai-product-tools' ), $conflicts ); } $url = admin_url( 'admin.php?page=aipt-history&tool=csv_import' ); echo '
' . esc_html( implode( ' ', $sentences ) ) . ' ' . esc_html__( 'View History', 'ai-product-tools' ) . '
'; echo '