Skip to content

Instantly share code, notes, and snippets.

@sikkgit
sikkgit / gist:2570204715a71f4bdaef12bf674254b9
Created January 26, 2023 18:26 — forked from MogulChris/gist:8fa67eedf01ef759e92e33a8e784aaa0
WooCommerce programmatically create variations from all attributes
<?php
/*
WooCommerce has a handy feature in the admin UI to "Create variations from all attributes".
To do this programmatically (as of WooCommerce v3.7.0) use a modified version of link_all_variations() found in woocommerce/includes/class-wc-ajax.php
*/
function myplugin_create_variations($product_id){
wc_maybe_define_constant( 'WC_MAX_LINKED_VARIATIONS', 50 );
wc_set_time_limit( 0 );