Database Structure

The data for Linked Variations are stored in these two database tables:

wp_posts: Linked Variations are presented as a Custom Post type with the key cpt_iconic_wlv.

wp_iconic_woo_linked_variations: The settings of Linked Variations such as product IDs, attributes, show images, etc., are stored in this custom table created by Linked Variation plugin. The database schema of this table is shown in the table below:

ColumnType
idint(11)
product_idslongtext NULL
attributeslongtext NULL
show_imagetinyint(1) NULL
post_idbigint(20) NULL
styletext NULL

Where product_ids and attributes are arrays stored in serialized format.

Programatically update Linked Variations

We have a helper function, Iconic_WLV_Database::update_linked_variations_meta, that can be used to programmatically insert/update linked variations with the PHP code. Creating a linked variation is a two-step process: First, create and insert a new post type, and then insert the linked variation data into the custom table wp_iconic_woo_linked_variations.

// Insert the post.
$post_id = wp_insert_post(
	array(
		'post_title' => 'new linked variation',
		'post_type'  => 'cpt_iconic_wlv',
	)
);

// Prepare linked variation data.
$data = array(
	'product_ids' => array( 30, 31 ),
	'attributes'  => array( 'pa_color' ),
	'show_image'  => 1,
	'post_id'     => $post_id,
	'style'       => 'button',
);

Iconic_WLV_Database::update_linked_variations_meta( $post_id, $data );

WooCommerce Linked Variations

Link a group of WooCommerce products together by attribute; a new way to handle product variations.

Was this helpful?

Please let us know if this article was useful. It is the best way to ensure our documentation is as helpful as possible.