Save default cat when saving products

This commit is contained in:
Mike Jolley 2017-11-23 14:26:43 +00:00
parent 3dc4277490
commit 8dea28e6c2
1 changed files with 9 additions and 3 deletions

View File

@ -585,15 +585,21 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
/**
* For all stored terms in all taxonomies, save them to the DB.
*
* @param WC_Product
* @param bool Force update. Used during create.
* @param WC_Product $product Product object.
* @param bool $force Force update. Used during create.
* @since 3.0.0
*/
protected function update_terms( &$product, $force = false ) {
$changes = $product->get_changes();
if ( $force || array_key_exists( 'category_ids', $changes ) ) {
wp_set_post_terms( $product->get_id(), $product->get_category_ids( 'edit' ), 'product_cat', false );
$categories = $product->get_category_ids( 'edit' );
if ( empty( $categories ) && get_option( 'woocommerce_default_category', 0 ) ) {
$categories = array( get_option( 'woocommerce_default_category', 0 ) );
}
wp_set_post_terms( $product->get_id(), $categories, 'product_cat', false );
}
if ( $force || array_key_exists( 'tag_ids', $changes ) ) {
wp_set_post_terms( $product->get_id(), $product->get_tag_ids( 'edit' ), 'product_tag', false );