英文:
Woocommerce add if Customer is Guest to New Order Emails
问题
使用WooCommerce,我已启用了访客结账选项。如果客户在结账时是访客,我想在新订单确认电子邮件中,在客户详细信息上方快速添加词语“访客”,以便迅速标识这位客户是访客而不是已注册用户。
/*
* @hooked WC_Emails::customer_details() 显示客户详细信息
* @hooked WC_Emails::email_address() 显示电子邮件地址
*/
do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email);
请注意,上述代码是用于实现此功能的代码示例,并且只是将“访客”添加到电子邮件中的一部分。如果您需要更多详细信息或实际实现此功能的代码,请提供更多上下文或要求。
英文:
Using Woocommerce I have guest checkout enabled. If a customer is a guest upon checkout, I'd like to then add the word "Guest" to the new order confirmation email right above customer details to quickly reference this customer was a guest and not a registered user already.
/*
* @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 );
答案1
得分: 1
add_action( 'woocommerce_email_customer_details', 'add_guest_label_to_email', 5, 4 );
function add_guest_label_to_email( $order, $sent_to_admin, $plain_text, $email ) {
// Check if customer is a guest
if ( ! $order->get_user_id() ) {
$guest_label = '
访客
';
echo $guest_label;
}
}
英文:
This should do it
add_action( 'woocommerce_email_customer_details', 'add_guest_label_to_email', 5, 4 );
function add_guest_label_to_email( $order, $sent_to_admin, $plain_text, $email ) {
// Check if customer is a guest
if ( ! $order->get_user_id() ) {
$guest_label = '<p><strong>Guest</strong></p>';
echo $guest_label;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论