I create custom plugin for import categories. now i have categories array from api.but when import categories into my wordpress woo commerce means not working.
My code is given below.
public function sample_insert_category() {
if(!term_exists('sample-category')) {
wp_insert_term(
'Sample Category',
'category',
array(
'description' => 'This is an sample category.',
'slug' => 'sample-category'
)
);
}
}
add_action( 'init', 'sample_insert_category' );
already i have used this code in function.php file. now i create a plugin. so i need to include this to my plugin. When i add this code into my plugin class means i got the warning.
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'admin_menu_top' not found or invalid function name
i want to add category and sub category using code.. help me anyone.