이 코드 예제에 따라 특정 제품에 대한 WooCommerce 이메일 알림을 비활성화합니다 (아직 댓글을 게시 할 수 없습니다) . 격리 된 제품에 대해 실행할 코드를 구현했습니다. 즉, 제품이 주문 ( $product_id == 5274
) 인 경우에만 이 코드가 작동합니다.
add_filter('woocommerce_email_recipient_new_order', 'remove_free_course_notifications', 10, 2);
function remove_free_course_notifications( $recipient, $order )
{
$page = $_GET['page'] = isset($_GET['page']) ? $_GET['page'] : '';
if ('wc-settings' === $page) {
return $recipient;
}
if (!$order instanceof WC_Order) {
return $recipient;
}
//my product id is 5274
$items = $order->get_items();
foreach ($items as $item) {
$product_id = $item['product_id'];
if ($product_id == 5274) {
$recipient = '';
}
return $recipient;
}
}
그러나 주문에 다른 항목 (제품)이 동시에있는 경우 관리자에게 알림이 전송되지 않습니다.
주문에 포함 된 나머지 항목에 대한 관리자 알림을 보내려면이 코드를 변경하는 방법을 알려주세요.
이 코드는 약간 구식입니다. 대신 다음을 사용하여 "독점"으로 정의 된 제품에 대한 새 주문 관리 알림을 중지하십시오.
add_filter( 'woocommerce_email_recipient_new_order', 'remove_free_course_notifications', 10, 2 );
function remove_free_course_notifications( $recipient, $order )
{
if ( ! is_a( $order, 'WC_Order' ) ) {
return $recipient;
}
$targeted_product_id = 5274; // Here set your product ID
$other_found = $product_found = false;
foreach ( $order->get_items() as $item ) {
$product_id = $item->get_product_id();
if ( $item->get_product_id() == $targeted_product_id ) {
$product_found = true;
} else {
$other_found = true;
}
}
if ( $product_found && ! $other_found ) {
return '';
}
return $recipient;
}
코드는 활성 자식 테마 (또는 활성 테마)의 functions.php 파일에 들어갑니다. 작동합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다