Answer the question
In order to leave comments, you need to log in
Why does this error occur when creating a subcategory for woocommerce products (creates twice)?
I have a function that creates categories for products.
when I try to use it to create subcategories and set parent, the product is created as the main product and gives an error that a similar product already exists.
function test(){
$sub_cat_id = wp_insert_term(
'TEST', // the term
'product_cat',
array(
'parent' => 7331
)
);
echo "------------------------------------" . "</br>";
if ( is_wp_error( $sub_cat_id ) ) {
echo "Error: " . $sub_cat_id->get_error_message() . "</br>";
echo "------------------------------------" . "</br>";
}
return null;
}
------------------------------------
Error: A term with the name provided already exists with this parent.
------------------------------------
Answer the question
In order to leave comments, you need to log in
wp_insert_term(
'TEST',
'product_cat',
array(
'description'=> 'test description',
'slug' => 'mytest',
'parent'=> 7331
)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question