Skip to content

Data & Competition State

Competition products use the WooCommerce competition product type and WC_Product_Competition. Read products with wc_get_product() and verify the product class before calling competition methods.

The actual table prefix follows the WordPress installation.

Table suffix Purpose
cfw_log Participant entries, orders, tickets, answers, dates
cfw_log_reserved Temporary ticket reservations with session and order association
cfw_instant_prizes Configured prize tickets, descriptions, values, categories, images
cfw_instantwin Recorded instant winners and related orders

Maintain these tables together with products, users, and orders in backups. Prize summaries and caches support storefront and Analytics queries; use the maintenance tools to rebuild them.

Important metadata includes _competition_dates_from, _competition_dates_to, _competition_min_tickets, _competition_max_tickets, _competition_winners, and _competition_closed.

The current lifecycle uses closed value 1 for failed competitions and 2 for successful closing. A temporary value can occur while closing is in progress. Do not determine state by casting the raw value to a boolean alone.

is_closed() can perform lifecycle work, including recording results and firing actions. Treat it as behavior rather than a side-effect-free reporting getter.

Current schema definitions use $wpdb->get_charset_collate() for new tables. Existing collations are not automatically migrated by that change. Use the plugin’s database repair and versioned maintenance paths rather than undocumented direct SQL writes.

The current database schema version is 2.5. Activation and upgrades from earlier versions call Competitions_For_Woocommerce_Activator::repair_database(). The repair uses a database lock, runs dbDelta(), and checks required definitions before updating competitions_for_woocommerce_database_version. A failed repair leaves the version unchanged for a later retry.

cfw_log_reserved.order_id is an unsigned BIGINT with a default of 0. Zero represents a session reservation that has not yet been linked to an order. Reservation cleanup and payment checks use order ownership so one order does not release another order’s hold.

Entry recording and prize replacement require InnoDB. Order entry processing records the validated lines in a transaction before participation callbacks. Reservation writes use a transaction or a savepoint within an existing transaction.

Use WooCommerce CRUD for orders so customizations remain compatible with HPOS.

CFW_Cache uses the group competitions_for_woocommerce, exposed by Competitions_For_Woocommerce::CACHE_GROUP. Query results use a 300-second TTL and versioned product keys from CFW_Cache::key(). Entry and prize changes invalidate the product namespace through CFW_Cache::invalidate() and the participant or instant-prize invalidation helpers.

Use these helpers after supported data writes instead of deleting legacy cache-key strings. Cache keys include query arguments such as the customer and history cutoff. Reservation availability is read from the database after expired holds are removed.

The saved competitions_for_woocommerce_non_persistent_cache preference defaults to no. When enabled, initialization registers the group through wp_cache_add_non_persistent_groups(). A mode change also changes competitions_for_woocommerce_cache_generation so old keys are no longer reused. The cache implementation must honor non-persistent groups. If it does not, configure an exclusion for competitions_for_woocommerce in the cache integration.

CFW_Csv::prize_batches() parses imports in batches of up to 500 rows or approximately 256 KiB of field data. replace_batches() stages rows in a temporary table with unique ticket numbers, then replaces the live pool in a transaction. It uses a per-competition database lock and preserves the existing pool if staging or replacement fails.

CFW_Csv::history_batches() snapshots the selected history into a temporary InnoDB table, ordered by date and ID. It yields pages of up to 500 rows. The woocomerce_competition_history and woocommerce_competition_history_data filters receive each page separately during export. Custom filters must not assume they receive the complete competition history in one call.

The database user needs permission to create temporary tables for these CSV paths. Participant export files use unique names and a temporary file before the final move. A failed required export prevents relisting.

Some ticket-selection paths build the available ticket pool in PHP. Memory use can therefore grow with the configured maximum ticket count.

Load-test the intended pool size and concurrent checkouts on staging, including a nearly sold-out competition. Monitor PHP memory errors and request times. Check reservation expiry, duplicate ticket prevention, and saved entry records before increasing production capacity.