コード例 #1
0
function tickets_shortcode()
{
    global $current_user;
    $email = $current_user->user_email;
    $tickets = new WC_Freshdesk_Tickets('https://library.thesmsfacademy.com.au/', 'ecQRnykjMLCZsasfkDnV', 0);
    $display = $tickets->tickets_table($email);
    //$display = $tickets->get_user_tickets( $email, 0 );
    //echo $tickets->tickets_table( $email );
    return $display;
}
 /**
  * Comments to ticket.
  *
  * @since  1.0.0
  *
  * @return void
  */
 public function comment_to_ticket()
 {
     if (!isset($_GET['commet_to_ticket'])) {
         return '';
     }
     global $wpdb;
     $comment_id = intval($_GET['commet_to_ticket']);
     // Get the post ID from the comment ID.
     $post_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT comment_post_ID\n\t\t\t\tFROM {$wpdb->comments}\n\t\t\t\tWHERE comment_ID = %d\n\t\t\t", $comment_id));
     // Stops if don't find a post id.
     if (empty($post_id)) {
         return '';
     }
     // Get the post type.
     $post_type = get_post_type($post_id);
     // Get the integration data.
     $integration = new WC_Freshdesk_Integration();
     // Sets the ticket params.
     $ticket = new WC_Freshdesk_Tickets($integration->url, $integration->api_key, $integration->debug);
     // Sets the ticket data.
     $comment = get_comment($comment_id);
     $email = $comment->comment_author_email;
     $subject = sprintf(__('Comment in %s at %s'), get_the_title($post_id), $comment->comment_date);
     $subject = apply_filters('woocommerce_freshdesk_ticket_from_comment_subject', $subject, $comment);
     $description = $comment->comment_content;
     $response = array('id' => 0, 'status' => 0);
     // Test the email.
     if (!is_email($email)) {
         wp_redirect(add_query_arg(array('ticket_status' => 2), esc_url(admin_url('edit-comments.php'))));
         exit;
     }
     // Test the content.
     if (empty($description)) {
         wp_redirect(add_query_arg(array('ticket_status' => 3), esc_url(admin_url('edit-comments.php'))));
         exit;
     }
     // Get post data.
     if ('product' == $post_type) {
         $order = null;
         $is_order = false;
         $order_id = $this->get_order_from_comment($comment->comment_author_email, $comment->user_id, $comment->comment_post_ID);
         if ($order_id) {
             $order = new WC_Order($order_id);
             $is_order = true;
         }
         $response = $ticket->open_ticket_from_comment($email, $subject, $description, $is_order, $order);
     } else {
         $response = $ticket->open_ticket_from_comment($email, $subject, $description);
     }
     // Redirects to avoid reloads and displaying the success message.
     wp_redirect(add_query_arg(array('ticket_status' => $response['status'], 'ticket_id' => $response['id']), esc_url(admin_url('edit-comments.php'))));
     exit;
 }
コード例 #3
0
 /**
  * Process the tickets by ajax.
  *
  * @since  1.0.0
  *
  * @return  string JSON data.
  */
 public function process_tickets()
 {
     check_ajax_referer('woocommerce_freshdesk_proccess_ticket', 'security');
     // Get the integration data.
     $integration = new WC_Freshdesk_Integration();
     // Sets the ticket params.
     $ticket = new WC_Freshdesk_Tickets($integration->url, $integration->api_key, $integration->debug);
     $order_id = isset($_POST['order_id']) ? $_POST['order_id'] : '';
     $subject = isset($_POST['subject']) ? $_POST['subject'] : '';
     $description = isset($_POST['description']) ? $_POST['description'] : '';
     // Valid the order_id field.
     if (empty($order_id)) {
         echo json_encode(array('status' => 0, 'message' => __('There was an error in the request, please reload this page and try again.', 'woocommerce-freshdesk')));
         die;
     }
     // Valid the subject field.
     if (empty($subject)) {
         echo json_encode(array('status' => 0, 'message' => __('Subject is a required field.', 'woocommerce-freshdesk')));
         die;
     }
     // Valid the description field.
     if (empty($description)) {
         echo json_encode(array('status' => 0, 'message' => __('Description is a required field.', 'woocommerce-freshdesk')));
         die;
     }
     do_action('woocommerce_freshdesk_process_tickets');
     // Try to open the ticket.
     $response = $ticket->open_ticket($order_id, $subject, $description);
     echo json_encode($response);
     die;
 }