Đã hoàn thành

PHP re-write Code Snippet

I need someone to rewrite the following snippet. This snippet handles different receiver per category.

The goal is: if in a order are products of more then 1 category, the order notification should only go to one email address. I guess for a php freak that isn't a big thing to optimize this snippet analogous my need.

// Custom conditional function that handle parent product categories too

function has_product_categories( $categories, $product_id = 0 ) {

$parent_term_ids = $categories_ids = array(); // Initializing

$taxonomy = 'product_cat';

$product_id = $product_id == 0 ? get_the_id() : $product_id;

if( is_string( $categories ) ) {

$categories = (array) $categories; // Convert string to array


// Convert categories term names and slugs to categories term ids

foreach ( $categories as $category ){

$result = (array) term_exists( $category, $taxonomy );

if ( ! empty( $result ) ) {

$categories_ids[] = reset($result);



// Loop through the current product category terms to get only parent main category term

foreach( get_the_terms( $product_id, $taxonomy ) as $term ){

if( $term->parent > 0 ){

$parent_term_ids[] = $term->parent; // Set the parent product category

$parent_term_ids[] = $term->term_id; // (and the child)

} else {

$parent_term_ids[] = $term->term_id; // It is the Main category term and we set it.



return array_intersect( $categories_ids, array_unique($parent_term_ids) ) ? true : false;


// Adding custom recipients based on product categories

add_filter( 'woocommerce_email_recipient_new_order', 'custom_email_recipient_new_order', 10, 2 );

function custom_email_recipient_new_order( $recipient, $order ) {

// Not in backend when using $order (avoiding an error)

if( ! is_a($order, 'WC_Order') ) return $recipient;

// Define the email recipients / categories pairs in the array

$recipients_categories = array(

'email1 @ com' => 'category-one',

'email2 @ com'' => 'category-two',

'email3 @ com'' => 'category-three',


// Loop through order items

foreach ( $order->get_items() as $item ) {

// Loop through defined product categories

foreach ( $recipients_categories as $email => $category ) {

if( has_product_categories( $item->get_product_id(), array( $category ) ) && strpos($recipient, $email) === false ) {

$recipient .= ',' . $email;




return $recipient;


Kĩ năng: PHP, MySQL, WordPress

Về khách hàng:
( 171 nhận xét ) Lyss, Switzerland

ID dự án: #34402034

Được trao cho:


⭐⭐⭐⭐⭐ Hello. I have rich experience in PHP. [login to view URL] [login to view URL] So I can rewrite snippet as you want. Please contact me to discuss more, looking forward to work with you. Thanks!

$20 USD trong 7 ngày
(3 Đánh Giá)

12 freelancer chào giá trung bình$22 cho công việc này

(161 Nhận xét)

--------- PLEASE GIVE ME A CHANCE TO WORK ON YOUR PROJECT --------- Dear Sir / Madam, I am Moffazzal from Rainsys. Rainsys is a Web & Software Development Company with 12 persons working together. We have 9+ years of Thêm

$10 USD trong 1 ngày
(86 Nhận xét)
(19 Nhận xét)

Hello Sir, We are experts of PHP development , having more then 8 years of experience. I am ready to work as per given description in best price Kindly PM me to discuss further

$10 USD trong 7 ngày
(57 Nhận xét)

Hello, I can do this. Kindly inbox me.

$20 USD trong 1 ngày
(3 Nhận xét)

Hi There, I hope you are doing well. Project - - I have read the description of your project and understood that you are looking for a website developed. I Have gone through your initial project requirement and I have Thêm

$20 USD trong 7 ngày
(15 Nhận xét)

Hi, Your posting for "PHP re-write Code Snippet" perfectly matches my expertise and experience. Having read the requirements carefully, I believe I can complete your project very nicely. I have extensive knowledge o Thêm

$20 USD trong 7 ngày
(0 Nhận xét)

Hello, I'm Suzan, professional Graphic Artist with skills including WordPress, PHP and MySQL. I have reviewed your project and I am qualified to carry it out with incredible goals for your fashion company. I will cre Thêm

$20 USD trong 1 ngày
(0 Nhận xét)

Hello there, ***I can build your PHP site I assured you 100% customer satisfaction guarantee I will provide you responsive website, high level graphics I have the 6+ years of experience in web development & design Thêm

$20 USD trong 7 ngày
(2 Nhận xét)

Hi, i have more than 7 years of experience in web development (php), so i can do the best for you. Thankyou

$20 USD trong 1 ngày
(0 Nhận xét)

I am gonna work with PHP with my own program . And it will be my pleasure to gain your trust from my first work with you.

$20 USD trong 7 ngày
(0 Nhận xét)