Я хочу добавить дополнительный текст «В этом конкретном элементе есть предложение и т. д.» Только для определенного продукта (Идентификатор продукта: 1) в customer-completed-order.php в WordPress. Другие продукты не нуждаются в этой дополнительной строке. Может ли кто-нибудь помочь мне узнать это?
<?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 printf( esc_html__( 'Your %s order has been marked complete on our side.', 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></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 );






Следующее будет отображать настраиваемый текст под названием позиции заказа для определенного продукта в электронном уведомлении о завершении клиентом:
// Setting the email_is as a global variable
add_action('woocommerce_email_before_order_table', 'the_email_id_as_a_global', 1, 4);
function the_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email ){
$GLOBALS['email_id_str'] = $email->id;
}
// Displaying product description in new email notifications
add_action( 'woocommerce_order_item_meta_end', 'product_description_in_new_email_notification', 10, 3 );
function product_description_in_new_email_notification( $item_id, $item, $order = null ){
// HERE define your targetted product ID
$targeted_id = 37;
// HERE define the text information to be displayed for the targeted product id
$text_information = __("There is an offer in this particular item", "woocommerce");
// Getting the email ID global variable
$refNameGlobalsVar = $GLOBALS;
$email_id = $refNameGlobalsVar['email_id_str'];
// If empty email ID we exit
if (empty($email_id)) return;
// Only for "New Order email notification" for your targeted product ID
if ( 'customer_completed_order' == $email_id &&
in_array( $targeted_id, array( $item->get_product_id(), $item->get_variation_id() ) ) ) {
// Display the text
echo '<div class = "product-text" style = "margin-top:10px"><p>' . $text_information . '</p></div>';
}
}
Код находится в файле function.php вашей активной дочерней темы (активной темы). Проверено и работает.
@sherin Нет ... Есть 2 способа: 1) В вашей активной дочерней теме (активной теме), куда вы добавите код в файл function.php… 2) Или с помощью плагина Фрагмент кода, вы вставите этот код ответа в новый фрагмент кода, тогда вы сохраните и активируете сниппет. Если для вас это слишком сложно, попробуйте связаться со мной в чате Skype, ища Лоик де Марсе (Париж).
Хорошо, я скопирую этот код и вставлю его в свою дочернюю тему function.php. По поводу $ target_id = 37; Я могу изменить свой идентификатор целевого продукта. Верно?
@sherin Да, конечно, как видите: «ЗДЕСЬ определите свой целевой идентификатор продукта»
Конечно. Посмотрю
Мой файл находится в mytheme / woocommerce / emails / customer-completed-order.php, могу ли я заменить этот файл на обновленный выше? И я не смог найти идентификатор продукта в приведенном выше коде. Извините, я только новичок.