$item) { $item_data = $item->get_data(); $post_terms = wp_get_object_terms($item->get_product_id(), 'template_category', array('fields' => 'id=>name')); if (!empty($post_terms) && !is_wp_error($post_terms)) { $cat = ''; $category_template_id = ''; foreach ($post_terms as $id => $term) { $cat = $term; $category_template_id = $id; } $template_category_object = new Wiaas_Template_Category_Object( $category_template_id, $cat, $item_data['quantity_max'], $item->get_id(), $item->get_title()); $template_category_objects[$category_template_id] = $template_category_object; } } return $template_category_objects; } /** * Save selected template to bundled product meta * * @param $selected_template integer * @param $post_id integer */ public static function bind_selected_template_to_product($selected_template, $post_id) { if (!empty($selected_template)) update_post_meta($post_id, '_select_template', esc_attr($selected_template)); else { update_post_meta($post_id, '_select_template', ''); } } /** * Save template categories to template product meta * * @param $post_id integer * @param $option string a main wiaas category * @param $processed_template_data array actual template category data */ public static function save_template_product_meta($post_id, $option, $processed_template_data) { update_post_meta($post_id, '_template_items_' . $option, $processed_template_data); } } } add_action('init', 'construct_template_products_class'); function woocommerce_product_class($classname, $product_type) { if ($product_type == 'wiaastemplate') { $classname = 'WC_Product_Template'; } return $classname; } add_filter('woocommerce_product_class', 'woocommerce_product_class', 10, 2);