wharfdale
wharfdale

Reputation: 752

How to load WooCommerce before my custom plugin

I have WooCommerce installed, and I am also building a custom plugin.

My custom plugin is running before WooCommerce because (from what I’ve read) they are loaded Alphabetically (unless using mu-plugin etc).

WooCommerce (when activated) adds a taxonomy: product_cat as normal.

My custom plugin has a function which is trying to use that taxonomy, but at this point the custom plugin has loaded before WooCommerce, so the taxonomy product_cat does not yet exist.

wp_set_object_terms( 1118, 41, 'product_cat', true );

So my error is: 0 => string ‘Invalid taxonomy.’ (length=17)

Upvotes: 2

Views: 2278

Answers (1)

Shakeel Ahmad
Shakeel Ahmad

Reputation: 349

You can use a hook that checks if WooCommerce is loaded first, and then execute your function like:

add_action( 'woocommerce_loaded', 'action_woocommerce_loaded', 10, 1 ); 

Upvotes: 5

Related Questions