'EmailKit', 'actions' => '', ) ); } return $array; } public function emailkit_column_template($email) { $wc_template_type = $email->id; $builder_url= ''; $demo_url = ''; $emailkit_email_type = ''; $emailkit_template_title = ''; $template_type = ''; // Get the post ID based on email type and template types $post_id = $this->get_emailkit_post_id($wc_template_type); $emailkit_template = $this->find_emailkit_template($wc_template_type); if (null === $post_id) { if (isset($emailkit_template)) { $demo_url = isset($emailkit_template['file']) ? $emailkit_template['file'] : ''; $emailkit_email_type = isset($emailkit_template['mail_type']) ? $emailkit_template['mail_type'] : ''; $emailkit_template_title = isset($emailkit_template['title']) ? $emailkit_template['title'] : ''; $template_type = isset($emailkit_template['template_type']) ? $emailkit_template['template_type'] : ''; } } else { $builder_url = admin_url("post.php?post={$post_id}&action=emailkit-builder"); } echo wp_kses( ' ', Utils::get_kses_array() ); } private function get_emailkit_post_id($wc_template_type) { $args = array( 'post_type' => 'emailkit', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', // Use AND relation for matching both conditions array( 'key' => 'emailkit_template_type', 'value' => $wc_template_type, ), /* array( 'key' => 'emailkit_template_status', 'value' => 'inactive', // Modify this value based on your requirements ), */ ), ); $query = new WP_Query($args); $post_ids = array(); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $post_ids[] = get_the_ID(); } wp_reset_postdata(); } // error_log(\print_r($post_ids,true)); // Return the first matching post ID return $post_ids[0]?? null; } function woocomerce_integration() { wp_enqueue_script("emailkit-admin-wc-js" , EMAILKIT_ADMIN . 'EmailSettings/Wcintegration.js' , ['jquery'], EMAILKIT_VERSION, true); wp_localize_script( 'emailkit-admin-wc-js', 'woocommerce', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce('emailkit_nonce'), 'rest_url' => esc_url(get_rest_url(null, 'emailkit/v1/')), 'rest_nonce' => wp_create_nonce('wp_rest') ) ); } function find_emailkit_template($wc_template_type) { $templates = TemplateList::get_templates(); $template_title = EmailLists::woocommerce_email($wc_template_type); foreach ($templates as $key => $value) { $email_type = $value['mail_type']; $template_email_type = $value['title']; if ($email_type == 'woocommerce' && $wc_template_type == $template_email_type) { return [ 'file' => $value['file'], 'mail_type' => $email_type, 'template_type' => $wc_template_type, 'title' => $template_title, ]; } } return []; } }