Php 在WooCommerce电子邮件通知文本中显示发货地址2
在WooCommerce结帐字段Php 在WooCommerce电子邮件通知文本中显示发货地址2,php,wordpress,woocommerce,orders,email-notifications,Php,Wordpress,Woocommerce,Orders,Email Notifications,在WooCommerce结帐字段配送地址\u 2,我建立了一张定制折扣券。我需要的是在特定的电子邮件通知中获取此订单字段值 以下是我的代码尝试: add_action( 'woocommerce_email_before_order_table', 'add_content_to_specific_email', 20, 4 ); function add_content_to_specific_email( $order, $sent_to_admin, $plain_text, $email
配送地址\u 2
,我建立了一张定制折扣券。我需要的是在特定的电子邮件通知中获取此订单字段值
以下是我的代码尝试:
add_action( 'woocommerce_email_before_order_table', 'add_content_to_specific_email', 20, 4 );
function add_content_to_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
if ( $email->id == 'customer_processing_order' ) {
echo '<h2 class="email-upsell-title">Get 20% off</h2><p class="email-upsell-p">Thank you for making this purchase! Come back and use the code "<strong> get_post_meta( $order_id, '_shipping_address_2', true ) </strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
}
}
add_action('woocommerce_email_前_订单_表','add_内容_至_特定_email',20,4);
功能将内容添加到特定电子邮件($order、$sent、$admin、$plain、$email){
如果($email->id=='customer\u processing\u order'){
echo“获得20%的折扣”感谢您购买此商品!请返回并使用代码“Get\u post\u meta($order\u id,“\u shipping\u address\u 2',true)”在下次购买时获得20%的折扣!单击此处继续购物。
”;
}
}
它不起作用。我想将此字段值转换为
html标记之间的字符串
欢迎您的帮助。您很快就能得到您所期望的。正确的答案是:
echo '<h2 class="email-upsell-title">Get 20% off</h2><p class="email-upsell-p">Thank you for making this purchase! Come back and use the code "<strong>' . get_post_meta( $order->ger_id(), '_shipping_address_2', true ) . '</strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';
代码进入活动子主题(或活动主题)的function.php文件。它应该可以工作。很酷!!非常感谢!!好多了!!您是否可以将其添加到已完成订单邮件中的相同函数“if($email->id='customer\u completed\u order'){}”中?@Carlos Claro!代码更新,为了处理客户处理和完成订单通知早上好,我尝试了代码,我得到了这个错误:语法错误,第5行出现意外的T_IF($优惠券代码=$order->get_shipping_address_2()){@CarlosGomez updated…对不起,第一个IF语句(第5行)缺少一个右括号谢谢!如果配送地址字段不为空,我只需要在邮件中留下文本,你能帮我吗?
add_action( 'woocommerce_email_before_order_table', 'add_content_to_specific_email', 20, 4 );
function add_content_to_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
// For customer processing and completed orders notifications
if ( in_array($email->id, ['customer_processing_order', 'customer_completed_order']) ) {
if( $coupon_code = $order->get_shipping_address_2() ) {
echo '<h2 class="email-upsell-title">'.__("Get 20% off").'</h2>
<p class="email-upsell-p">';
printf(
__("Thank you for making this purchase! Come back and use the code %s to receive a 20%% discount on your next purchase! %s."),
'"<strong>'.$coupon_code.'</strong>"',
'<a href="'. get_permalink( wc_get_page_id( 'shop' ) ) .'">' . __("Click here to continue shopping") . '</a>'
);
echo '</p>';
}
}
}