Woocommerce의 "주문 완료"이메일에 고유 한 텍스트를 추가하고 싶지만 구매 한 제품에 특정 제품 태그가있는 경우에만 해당됩니다. 구매 한 항목에 "모금 행사"태그가있는 경우 이메일에 우리의 기금 모금 행사를 지원 해주신 것에 대한 감사의 글을 포함하고 싶습니다. 긴 이야기지만이를 위해 카테고리를 사용할 수 없으며 태그를 사용해야합니다.
customer-complete-order.php 파일을 편집 해 보았는데 이것이 작동하지만 PHP 코드가 좋지 않으며 태그를 호출하는 방법에 대한 예가 없습니다.
나는 또한 다른 사람이 한 일을 기반으로 functions.php 편집을 시도했으며 이것은 내가 얻은 한입니다.
function woocommerce_custom_email_per_product_depending_on_product_tag( $email_heading, $order ) {
global $woocommerce;
$items = $order->get_items();
foreach ( $items as $item ) {
$product_tag = $item['product_tag'];
if ( $product_tag == fundraiser ) {
$email_body = 'Thanks for buying a fundraiser.';
}
return $email_heading;
} }
또는 새 이메일 템플릿에서이 사용자 정의 텍스트를 정의하는 것이 더 좋을까요? 다음은 woocommerce가 제공하는 주문 확인 템플릿입니다.
<?php
/**
* Customer completed order email
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-completed-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/
* @package WooCommerce/Templates/Emails
* @version 3.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/*
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Site title */ ?>
<p><?php esc_html_e( 'We have finished processing your order.', 'woocommerce' ); ?></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 );
?>
<p>
<?php esc_html_e( 'Thanks for shopping with us.', 'woocommerce' ); ?>
</p>
<?php
/*
* @hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
function woocommerce_custom_email_per_product_depending_on_product_tag( $order, $sent_to_admin, $plain_text, $email ) {
$items = $order->get_items();
foreach ( $items as $item ) {
// get an array of the WP_Term objects for a defined product ID
$terms = wp_get_post_terms( $item['product_id'], 'product_tag' );
foreach($terms as $term){
$term_names[] = $term->name; // Product tag Name
//$term->term_id; Product tag Id
//$term->slug; Product tag slug
}
}
if ( $email->id == 'customer_processing_order' && in_array('Fundraiser', $term_names) ) {
echo 'Thanks for buying a fundraiser.';
}
}
add_action( 'woocommerce_email_before_order_table', 'woocommerce_custom_email_per_product_depending_on_product_tag', 10, 4 );
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다