public static function email_inquiry($product_id, $your_name, $your_email, $your_phone, $your_message, $send_copy_yourself = 1) { global $wc_email_inquiry_contact_form_settings; $wc_email_inquiry_contact_success = stripslashes(get_option('wc_email_inquiry_contact_success', '')); if (WC_Email_Inquiry_Functions::check_add_email_inquiry_button($product_id)) { if (trim($wc_email_inquiry_contact_success) != '') { $wc_email_inquiry_contact_success = wpautop(wptexturize($wc_email_inquiry_contact_success)); } else { $wc_email_inquiry_contact_success = __("Thanks for your inquiry - we'll be in touch with you as soon as possible!", 'wc_email_inquiry'); } $to_email = $wc_email_inquiry_contact_form_settings['inquiry_email_to']; if (trim($to_email) == '') { $to_email = get_option('admin_email'); } if ($wc_email_inquiry_contact_form_settings['inquiry_email_from_address'] == '') { $from_email = get_option('admin_email'); } else { $from_email = $wc_email_inquiry_contact_form_settings['inquiry_email_from_address']; } if ($wc_email_inquiry_contact_form_settings['inquiry_email_from_name'] == '') { $from_name = get_option('blogname'); } else { $from_name = $wc_email_inquiry_contact_form_settings['inquiry_email_from_name']; } $cc_emails = $wc_email_inquiry_contact_form_settings['inquiry_email_cc']; if (trim($cc_emails) == '') { $cc_emails = ''; } $headers = array(); $headers[] = 'MIME-Version: 1.0'; $headers[] = 'Content-type: text/html; charset=' . get_option('blog_charset'); $headers[] = 'From: ' . $from_name . ' <' . $from_email . '>'; $headers_yourself = $headers; if (trim($cc_emails) != '') { $cc_emails_a = explode(",", $cc_emails); if (is_array($cc_emails_a) && count($cc_emails_a) > 0) { foreach ($cc_emails_a as $cc_email) { $headers[] = 'Cc: ' . $cc_email; } } else { $headers[] = 'Cc: ' . $cc_emails; } } $product_name = get_the_title($product_id); $product_url = get_permalink($product_id); $subject = __('Email inquiry for', 'wc_email_inquiry') . ' ' . $product_name; $subject_yourself = __('[Copy]: Email inquiry for', 'wc_email_inquiry') . ' ' . $product_name; $content = ' <table width="99%" cellspacing="0" cellpadding="1" border="0" bgcolor="#eaeaea"><tbody> <tr> <td> <table width="100%" cellspacing="0" cellpadding="5" border="0" bgcolor="#ffffff"><tbody> <tr bgcolor="#eaf2fa"> <td colspan="2"><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px"><strong>' . __('Name', 'wc_email_inquiry') . '</strong></font> </td></tr> <tr bgcolor="#ffffff"> <td width="20"> </td> <td><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px">[your_name]</font> </td></tr> <tr bgcolor="#eaf2fa"> <td colspan="2"><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px"><strong>' . __('Email Address', 'wc_email_inquiry') . '</strong></font> </td></tr> <tr bgcolor="#ffffff"> <td width="20"> </td> <td><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px"><a target="_blank" href="mailto:[your_email]">[your_email]</a></font> </td></tr> <tr bgcolor="#eaf2fa"> <td colspan="2"><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px"><strong>' . __('Phone', 'wc_email_inquiry') . '</strong></font> </td></tr> <tr bgcolor="#ffffff"> <td width="20"> </td> <td><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px">[your_phone]</font> </td></tr> <tr bgcolor="#eaf2fa"> <td colspan="2"><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px"><strong>' . __('Product Name', 'wc_email_inquiry') . '</strong></font> </td></tr> <tr bgcolor="#ffffff"> <td width="20"> </td> <td><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px"><a target="_blank" href="[product_url]">[product_name]</a></font> </td></tr> <tr bgcolor="#eaf2fa"> <td colspan="2"><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px"><strong>' . __('Message', 'wc_email_inquiry') . '</strong></font> </td></tr> <tr bgcolor="#ffffff"> <td width="20"> </td> <td><font style="FONT-FAMILY:sans-serif;FONT-SIZE:12px">[your_message]</font> </td></tr></tbody></table></td></tr></tbody></table>'; $content = str_replace('[your_name]', $your_name, $content); $content = str_replace('[your_email]', $your_email, $content); $content = str_replace('[your_phone]', $your_phone, $content); $content = str_replace('[product_name]', $product_name, $content); $content = str_replace('[product_url]', $product_url, $content); $your_message = str_replace('://', ':­//', $your_message); $your_message = str_replace('.com', '­.com', $your_message); $your_message = str_replace('.net', '­.net', $your_message); $your_message = str_replace('.info', '­.info', $your_message); $your_message = str_replace('.org', '­.org', $your_message); $your_message = str_replace('.au', '­.au', $your_message); $content = str_replace('[your_message]', wpautop($your_message), $content); $content = apply_filters('wc_email_inquiry_inquiry_content', $content); // Filters for the email add_filter('wp_mail_from', array('WC_Email_Inquiry_Functions', 'get_from_address')); add_filter('wp_mail_from_name', array('WC_Email_Inquiry_Functions', 'get_from_name')); add_filter('wp_mail_content_type', array('WC_Email_Inquiry_Functions', 'get_content_type')); wp_mail($to_email, $subject, $content, $headers, ''); // Unhook filters remove_filter('wp_mail_from', array('WC_Email_Inquiry_Functions', 'get_from_address')); remove_filter('wp_mail_from_name', array('WC_Email_Inquiry_Functions', 'get_from_name')); remove_filter('wp_mail_content_type', array('WC_Email_Inquiry_Functions', 'get_content_type')); return $wc_email_inquiry_contact_success; } else { return __("Sorry, this product don't enable email inquiry.", 'wc_email_inquiry'); } }
public static function details_add_email_inquiry_button_below($template_name, $template_path, $located, $args) { global $post; global $product; if (in_array($template_name, array('single-product/add-to-cart/simple.php', 'single-product/add-to-cart/grouped.php', 'single-product/add-to-cart/external.php', 'single-product/add-to-cart/variable.php'))) { $product_id = $product->id; if (($post->post_type == 'product' || $post->post_type == 'product_variation') && WC_Email_Inquiry_Functions::check_add_email_inquiry_button($product_id)) { echo WC_Email_Inquiry_Hook_Filter::add_email_inquiry_button($product_id); } } }