Я скопировал файл шаблона электронной почты в папку моей темы:
mytheme/woocommerce/emails/customer-completed-order.php
Затем я изменил этот файл на:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<?php
$items = $order->get_items();
foreach ($items as $key => $item) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$terms = get_the_terms( $product_id, 'product_cat' );
// echo var_dump($terms);
foreach ( $terms as $term ) {
// Categories by slug
$product_cat_id= $term->id;
}
}
if ($product_cat_id = "65") {
?>
<?php
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>title...</title>
<style>
...
HTML email template codes...
...
<?php } else { ?>
<?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
do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email );
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
if ( $additional_content ) {
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}
do_action( 'woocommerce_email_footer', $email );
Как видите, я хотел использовать этот пользовательский шаблон для продуктов категории "65". Но заказ не может быть обработан и возвращает ошибку сервера. Я здесь ошибаюсь?