\d+)', array( 'methods' => 'GET', 'permission_callback' => 'check_permission', 'callback' => 'fetch_user_by_id', )); }); add_action('rest_api_init', function () { register_rest_route('wiaas/v1', '/user', array( 'methods' => 'GET', 'permission_callback' => 'check_permission', 'callback' => 'fetch_user_by_id', )); }); add_action('added_post_meta', 'check_template_on_product_save', 1, 3); add_action('updated_post_meta', 'check_template_on_product_save', 1, 3); function check_template_on_product_save($meta_id, $post_id, $meta_key) { if ($meta_key == '_edit_lock' && get_post_type($post_id) == 'product') { $product = wc_get_product($post_id); if ($product->is_type('grouped')) { $nested_products = $product->get_children(); $template_categories = []; $template_product_id = 0; foreach ($nested_products as $nested_product_id) { $categories = wp_get_post_terms($nested_product_id, 'product_cat', array('fields' => 'names')); if ((in_array("Templates", $categories))) { error_log("There are templates in array"); $template_product_id = $nested_product_id; foreach ($categories as $category) { error_log($category); if ($category !== "Templates") { error_log($category); $template_categories[$category] = 0; } } } } if (!empty($template_categories)) { error_log("Template product categories"); foreach ($nested_products as $nested_product_id) { error_log("PRODUCT ID =="); error_log($nested_product_id); $categories_new = wp_get_post_terms($nested_product_id, 'product_cat', array('fields' => 'names')); if ((in_array($categories_new[0], $template_categories))) { error_log("Found template category in package"); error_log($categories_new[0]); if ($template_product_id !== $nested_product_id) { $template_categories[$categories_new[0]]++; } } } foreach ($template_categories as $index) { error_log("INDEX =="); error_log($index); if ($index === 0) { set_transient('sample_admin_notice__error', true, 5); add_action('admin_notices', 'sample_admin_notice__error'); } } } unset($template_categories); } } } function sample_admin_notice__error() { $class = 'notice notice-error'; $message = __('This package is missing product categories that are required by template .', 'sample-text-domain'); printf('
%2$s