2017-08-26 74 views
1

當前電子郵件附在此處。我想添加一行說「賣家資源轉到www.domain.com/slug」。我如何將此文本添加到此電子郵件的鏈接? (我有旁邊0 PHP的技能,但試圖學習)。將簡單文本添加到Woocommerce電子郵件

enter image description here

if (! defined('ABSPATH')) { 
    exit; // Exit if accessed directly 
} 

?> 

<?php do_action('woocommerce_email_header', $email_heading, $email); ?> 

    <p><?php printf(__('Thanks for creating an account on %1$s. Your username is %2$s', 'woocommerce'), esc_html($blogname), '<strong>' . esc_html($user_login) . '</strong>'); ?></p> 

<?php if ('yes' === get_option('woocommerce_registration_generate_password') && $password_generated) : ?> 

    <p><?php printf(__('Your password has been automatically generated: %s', 'woocommerce'), '<strong>' . esc_html($user_pass) . '</strong>'); ?></p> 

<?php endif; ?> 

    <p><?php printf(__('You can access your account area to view your orders and change your password here: %s.', 'woocommerce'), make_clickable(esc_url(wc_get_page_permalink('myaccount')))); ?></p> 

<?php do_action('woocommerce_email_footer', $email); 
+1

您希望在哪裏添加新的代碼?有兩個動作鉤子,'woocommerce_email_header'和'woocommerce_email_footer',可能可以用於。 – helgatheviking

+0

我很想在「謝謝創建賬戶」一行之後添加它。我可以只複製當前<?php if(語句,但輸入我自己的消息)的格式? 感謝! –

回答

0

你可以嘗試加入這個片段到你的主題functions.php或最好在特定的網站插件:

function so_45897243_add_text_to_email($email) { 
    if('customer_new_account' == $email->id) { 
     echo "for seller resources go to www.domain.com/slug."; 
    } 
} 
add_action('woocommerce_email_footer', 'so_45897243_add_text_to_email', 5); 

您可能還需要

function so_45897243_add_text_to_email_plain($text) { 
    $new = "for seller resources go to www.domain.com/slug."; 
    return $new . "\n\n" . $text; 
} 
add_filter('woocommerce_email_footer_text', 'so_45897243_add_text_to_email_plain'); 

爲純文本電子郵件,但目前似乎沒有辦法限制它添加了哪些電子郵件。

或者您可以覆蓋主題中的emails/customer-new-account.phpemails/plain/customer-new-account.php模板。然後你可以直接添加你的文字。我儘量保持我的模板覆蓋率爲最低限度,因爲它將使WooCommerce在未來更容易升級。

編輯樣品覆蓋模板:

<?php 
/** 
* Customer new account email 
* 
* Save this template in yourtheme/woocommerce/emails/customer-new-account.php. 
* 
* @see   https://docs.woocommerce.com/document/template-structure/ 
* @author  WooThemes 
* @package  WooCommerce/Templates/Emails 
* @version  1.6.4 
*/ 

if (! defined('ABSPATH')) { 
    exit; // Exit if accessed directly 
} 

?> 

<?php do_action('woocommerce_email_header', $email_heading, $email); ?> 

    <p><?php printf(__('Thanks for creating an account on %1$s. Your username is %2$s', 'your-theme'), esc_html($blogname), '<strong>' . esc_html($user_login) . '</strong>'); ?></p> 

    <p><?php _e('For seller resources go to <a href="http://wwww.domain.com/slug">www.domain.com/slug</a>.', 'your-theme'); ?></p> 

<?php if ('yes' === get_option('woocommerce_registration_generate_password') && $password_generated) : ?> 

    <p><?php printf(__('Your password has been automatically generated: %s', 'your-theme'), '<strong>' . esc_html($user_pass) . '</strong>'); ?></p> 

<?php endif; ?> 

    <p><?php printf(__('You can access your account area to view your orders and change your password here: %s.', 'your-theme'), make_clickable(esc_url(wc_get_page_permalink('myaccount')))); ?></p> 

<?php do_action('woocommerce_email_footer', $email); 
+0

感謝您的信息!我基本上有0 PHP知識,並嘗試在我學習時一起破解。太多的直接覆蓋(儘管這可以在兒童主題中起作用)。現在,如果我只是在該cutomer-new-account.php文件中輸入額外的一行,我該如何解決這個問題?謝謝! –

+0

Docs在[覆蓋模板]上(https://docs.woocommerce.com/document/template-structure/)。一旦將相關模板複製到主題中,您可以在需要的地方添加文字。 – helgatheviking

+0

謝謝 - 我只是不知道如何在覆蓋中實際編寫php代碼 –

相關問題