Php 在新订单电子邮件通知中添加自定义链接

Php 在新订单电子邮件通知中添加自定义链接,php,wordpress,templates,woocommerce,email-notifications,Php,Wordpress,Templates,Woocommerce,Email Notifications,我正在建立一个餐馆网站。在该网站的前一个版本中,当有人想要送货时,餐馆收到的邮件中,我有一个指向谷歌地图的链接。餐厅可以很容易地使用它导航到餐厅的客户。 现在我正在更改网站,我将与woocommerce合作,但我还希望在管理邮件中提供指向谷歌地图的链接 来自旧站点的代码。(带有谷歌地图链接的超链接,名为“Map It”。) 要在woocommerce中执行此操作,我需要更改woocommerce管理新订单的模板,在地址下方添加超链接,但我不知道如何执行此操作 模板admin-new-orde

我正在建立一个餐馆网站。在该网站的前一个版本中,当有人想要送货时,餐馆收到的邮件中,我有一个指向谷歌地图的链接。餐厅可以很容易地使用它导航到餐厅的客户。 现在我正在更改网站,我将与woocommerce合作,但我还希望在管理邮件中提供指向谷歌地图的链接

来自旧站点的代码。(带有谷歌地图链接的超链接,名为“Map It”。)


要在woocommerce中执行此操作,我需要更改woocommerce管理新订单的模板,在地址下方添加超链接,但我不知道如何执行此操作

模板admin-new-order.php:

<?php
/**
 * Admin new order email
 *
 * This template can be overridden by copying it to 
yourtheme/woocommerce/emails/admin-new-order.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and 
you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it 
does
 * happen. When this occurs the version of the template file will be bumped 
and
* the readme will list any important changes.
*
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author WooThemes
 * @package WooCommerce/Templates/Emails/HTML
 * @version 2.5.0
 */

 if ( ! defined( 'ABSPATH' ) ) {
    exit;
 }

 /**
  * @hooked WC_Emails::email_header() Output the email header
  */
 do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

 <p><?php printf( __( 'You have received an order from %s. The order is as 
follows:', 'woocommerce' ), $order->get_formatted_billing_full_name() ); ?> 
</p>

 <?php

 /**
  * @hooked WC_Emails::order_details() Shows the order details table.
  * @hooked WC_Structured_Data::generate_order_data() Generates structured 
data.
  * @hooked WC_Structured_Data::output_structured_data() Outputs structured 
data.
   * @since 2.5.0
  */
 do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, 
$plain_text, $email );

/**
  * @hooked WC_Emails::order_meta() Shows order meta data.
 */
 do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, 
  $plain_text, $email );

  /**
  * @hooked WC_Emails::customer_details() Shows customer details
  * @hooked WC_Emails::email_address() Shows email address
  */
 do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, 
 $plain_text, $email );

 /**
  * @hooked WC_Emails::email_footer() Output the email footer
 */
 do_action( 'woocommerce_email_footer', $email );



更新:如果需要在管理员“新订单”通知的页脚中添加,请使用以下命令:

add_action ('woocommerce_email_order_details', 'including_global_email_data', 2, 4 );
function including_global_email_data( $order, $sent_to_admin, $plain_text, $email ){
    // Set global email variable
    $GLOBALS['email_data'] = array( 'email' => $email, 'admin' => $sent_to_admin );
}

add_filter ('woocommerce_email_footer_text', 'custom_email_footer_text', 20, 1 );
function custom_email_footer_text( $footer_text ){
    // Get global variables
    $refNameGlobalsVar = $GLOBALS;
    $sent_to_admin = $refNameGlobalsVar['email_data']['admin'];
    $email         = $refNameGlobalsVar['email_data']['email'];

    // Only for admin "New order" email notification
    if( $email->id === 'new_order' ) // Or also:  if( $sent_to_admin )
    {
    $footer_text .= '<br><a href="http://maps.google.com/maps?q=nieuwstraat+15+brussel+1000+Belgium" class="m_8816063166882312894map-it-link" target="_blank" data-saferedirecturl="https://www.google.com/url?q=http://maps.google.com/maps?q%3Dnieuwstraat%2B15%2Bbrussel%2B1000%2BBelgium&amp">Map It</a>';
    }
    return $footer_text;
}
add_action('woocommerce_email_order_details','include_global_email_data',2,4);
功能包括全局电子邮件数据($order,$sent,$to,$admin,$plain,$email){
//设置全局电子邮件变量
$GLOBALS['email\u data']=数组('email'=>$email,'admin'=>$sent\u to\u admin);
}
添加过滤器('woocommerce\u email\u footer\u text','custom\u email\u footer\u text',20,1);
功能自定义\电子邮件\页脚\文本($页脚\文本){
//获取全局变量
$refnamelobalsvar=$GLOBALS;
$sent_to_admin=$refNameGlobalsVar['email_data']['admin'];
$email=$refNameGlobalsVar['email_data']['email'];
//仅适用于管理员“新订单”电子邮件通知
if($email->id=='new\u order')//或者:if($sent\u to\u admin)
{
$footer_text.='
'; } 返回$footer\u文本; }

代码进入活动子主题(或活动主题)的function.php文件。经过测试,效果良好。

非常感谢,这对我已经有很大帮助了!但是我需要订单的账单地址信息来代替链接中的静态地址信息。“Nieuwstraat 15 Brussel 1000比利时”只是一个例子。
add_action ('woocommerce_email_order_details', 
'including_global_email_data', 2, 4 );
function including_global_email_data( $order, $sent_to_admin, $plain_text, 
$email ){
    // Set global email variable
    $GLOBALS['email_data'] = array( 'email' => $email, 'admin' => 
$sent_to_admin,'order' =>$order );
}

add_filter ('woocommerce_email_footer_text', 'custom_email_footer_text', 20, 
1 );
function custom_email_footer_text( $footer_text ){
    // Get global variables
    $refNameGlobalsVar = $GLOBALS;
    $sent_to_admin = $refNameGlobalsVar['email_data']['admin'];
    $email         = $refNameGlobalsVar['email_data']['email'];
    $order         = $refNameGlobalsVar['email_data']['order'];

    // Only for admin "New order" email notification
    if( $email->id === 'new_order' ) // Or also:  if( $sent_to_admin )
    {
    $urltemp.=$order->billing_address_1.' '.$order->billing_address_2.' 
'.$order->billing_city.' '.$order->billing_postcode.' '.$order- 
    >billing_country;
    $urltemp=str_replace(" ","+",$urltemp);
    $urltemp='http://maps.google.com/maps?q='.$urltemp;
    $footer_text.='<br><a href="'.$urltemp.'" 
class="m_8816063166882312894map-it-link" target="_blank" data- 
   saferedirecturl="'.$urltemp.'&amp">Map It</a>';
    }
    return $footer_text;
}
add_action ('woocommerce_email_order_details', 'including_global_email_data', 2, 4 );
function including_global_email_data( $order, $sent_to_admin, $plain_text, $email ){
    // Set global email variable
    $GLOBALS['email_data'] = array( 'email' => $email, 'admin' => $sent_to_admin );
}

add_filter ('woocommerce_email_footer_text', 'custom_email_footer_text', 20, 1 );
function custom_email_footer_text( $footer_text ){
    // Get global variables
    $refNameGlobalsVar = $GLOBALS;
    $sent_to_admin = $refNameGlobalsVar['email_data']['admin'];
    $email         = $refNameGlobalsVar['email_data']['email'];

    // Only for admin "New order" email notification
    if( $email->id === 'new_order' ) // Or also:  if( $sent_to_admin )
    {
    $footer_text .= '<br><a href="http://maps.google.com/maps?q=nieuwstraat+15+brussel+1000+Belgium" class="m_8816063166882312894map-it-link" target="_blank" data-saferedirecturl="https://www.google.com/url?q=http://maps.google.com/maps?q%3Dnieuwstraat%2B15%2Bbrussel%2B1000%2BBelgium&amp">Map It</a>';
    }
    return $footer_text;
}