Save default cat when saving products
This commit is contained in:
parent
3dc4277490
commit
8dea28e6c2
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue