Skip to content

Instantly share code, notes, and snippets.

@WPprodigy
Created February 13, 2018 21:03
Show Gist options
  • Save WPprodigy/f70ff7ebf62fbfdf873ffedd6ca139d1 to your computer and use it in GitHub Desktop.
Save WPprodigy/f70ff7ebf62fbfdf873ffedd6ca139d1 to your computer and use it in GitHub Desktop.
Change default product category.
add_action( 'init', 'wc_ninja_update_default_category_once' );
function wc_ninja_update_default_category_once() {
// 20 = new default category ID
update_option( 'default_product_cat', '20' );
}
@WPprodigy
Copy link
Author

WPprodigy commented Feb 14, 2018

WooCommerce 3.3.2 will have a way to set a different category as the default. Until then, here's a quick workaround.

  1. Add this PHP snippet to your site, perhaps use the Code Snippets plugin mentioned here:
    https://calebburks.com/correctly-add-custom-code-woocommerce/

  2. Replace '20' with the category ID that you want to become the new default category.

  3. Refresh the page, then delete this snippet. (only needs to run once)

  4. If you want, you can then delete the previous default / "uncategorized" category.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment