Пользовательская электронная почта Woocommerce

Мне нужна помощь с настраиваемой электронной почтой для woocommerce.

Я пытаюсь отправить другое электронное письмо в зависимости от идентификатора продукта всякий раз, когда продукт завершен.

Мой код, который не работает, выглядит следующим образом:

/**************
DIFFERENT MESSAGES FOR DIFFERENT PRODUCTS
****************/

//hook our function to the new order email
add_action('woocommerce_email_order_details',     'uiwc_email_order_details_products', 1, 4);

function uiwc_email_order_details_products($order, $admin, $plain, $email) {
 $status = $order->get_status();

 // checking if it's the order status we want
  if ( $status == "completed" ) {
   $items = $order->get_items();

    if ( $item['product_id'] == "3181") {
      echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>To get started, please follow <a href="https:XXXXX">this link</a> to complete the Policies form.<br><br>This is a really important first step, and only takes about 5 minutes.  After completeing the Policies form, you will receive additional instructions on next steps.<br><br>Congratulations! Let your journey begin.<br><br>', 'uiwc' );
  }

   elseif ( $item['product_id'] == "3223") {
      echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>Differnet product so differenct email....<br><br>', 'uiwc' );
  }
}  
}

Любые предложения приветствуются


person Afill    schedule 03.11.2018    source источник
comment
Добро пожаловать в СО. Обращаясь за помощью, важно не просто сказать, что это не работает, но и объяснить, каков ваш ожидаемый результат и чем результаты, полученные вашим кодом, отличаются от этого. Прочтите stackoverflow.com/help/how-to-ask.   -  person Nick    schedule 03.11.2018
comment
Что вы подразумеваете под продуктом завершенным? Вы имеете в виду, что заказ выполнен?   -  person melvin    schedule 03.11.2018
comment
@Nick (это работает на SO?) Спасибо за совет. В следующий раз я буду более описательным в своем описании проблемы. Спасибо за терпение.   -  person Afill    schedule 03.11.2018
comment
@melvin, перечитав мой вопрос, ты прав - это не имеет смысла. Вы догадались, хотя, я имел в виду, когда заказ будет выполнен.   -  person Afill    schedule 03.11.2018


Ответы (1)


В вашем коде есть некоторые ошибки, вместо этого попробуйте следующее

//hook our function to the new order email
add_action( 'woocommerce_email_order_details', 'custom_email_order_details', 4, 4 );
function custom_email_order_details( $order, $admin, $plain, $email ) {
    $domain = 'woocommerce';

    // checking if it's the order status we want
    if ( $order->has_status('completed') ) {
        foreach( $order->get_items() as $item ){
            if ( $item->get_product_id() == '3181' ) {
                echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>To get started, please follow <a href="https://xxxxxx">this link</a> to complete the Policies form.<br><br>This is a really important first step, and only takes about 5 minutes. After completeing the Policies form, you will receive additional instructions on next steps.<br><br>Congratulations! Let your journey begin.<br><br>', $domain );
                break;
            }
            elseif ( $item->get_product_id() == '3223' ) {
                echo __( '<strong>IMPORTANT - NEXT STEP:</strong><br>Differnet product so differenct email....<br><br>', $domain );
                break;
            }
        } 
    }  
}

Код находится в файле function.php вашей активной дочерней темы (или активной темы). Проверено и работает.

person LoicTheAztec    schedule 03.11.2018
comment
Большое спасибо за помощь. Это было именно то, что я искал, и это сработало отлично. Чего вы не видели, так это 5 часов попыток и повторных попыток этого хука без успеха, прежде чем радуйся, ТАК, так что еще раз спасибо. Однако у меня есть последний вопрос... если бы я хотел добавить дополнительные продукты, я мог бы скопировать и вставить последний оператор elseif и соответствующим образом изменить идентификатор продукта, правильно? - person Afill; 03.11.2018