Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 根据WooCommerce订单项目产品标签更改PayPal电子邮件_Php_Wordpress_Woocommerce_Paypal_Taxonomy Terms - Fatal编程技术网

Php 根据WooCommerce订单项目产品标签更改PayPal电子邮件

Php 根据WooCommerce订单项目产品标签更改PayPal电子邮件,php,wordpress,woocommerce,paypal,taxonomy-terms,Php,Wordpress,Woocommerce,Paypal,Taxonomy Terms,我正在设法找到解决我问题的办法。我想更改基于WooCommerce产品标签的PayPal电子邮件。 例如:对于衣服、鞋类和包标签,请在电子邮件中emailpaypal1@domain.com ..... 如果标签是“雪”、“太阳”、“花园”,那么请将电子邮件paypal2@domain.com等等 我在几次搜索后发现了这段代码,但我无法让它与标记一起工作。我都试过了,但都失败了:(.谁能给我修改过的标签代码吗?非常感谢!! 更新 我把它放在子主题的function.php文件中,但它在我附加给

我正在设法找到解决我问题的办法。我想更改基于WooCommerce产品标签的PayPal电子邮件。 例如:对于衣服、鞋类和包标签,请在电子邮件中emailpaypal1@domain.com ..... 如果标签是“雪”、“太阳”、“花园”,那么请将电子邮件paypal2@domain.com等等

我在几次搜索后发现了这段代码,但我无法让它与标记一起工作。我都试过了,但都失败了:(.谁能给我修改过的标签代码吗?非常感谢!!

更新 我把它放在子主题的
function.php
文件中,但它在我附加给你的那行中给了我一个错误。我复制得不好吗?:(.我忘了什么吗?非常感谢

Error: syntax error, unexpected 'array' (T_ARRAY), expecting ')' 

他在这一行给我的错误…但老实说,我不知道wordpress的程序是否理解这一行,或者你是否错了:(.这并不能让我保存这个问题的代码

Error: syntax error, unexpected 'array' (T_ARRAY), expecting ')'

要处理订单项目上的特定产品标签,您可以使用WordPress
的_term()
函数,将第一个挂钩函数替换为以下函数:

add_filter( 'woocommerce_paypal_args' , 'switch_paypal_email_based_product_tags', 9999, 2 );
function switch_paypal_email_based_product_tags( $paypal_args, $order ) {
    // Here define your product tags
    $tag_terms1 = array('clothing', 'footwear', 'bags'); 
    $tag_terms2 = array('snow', 'sun', 'garden');

    // Here define your emails
    $email1     = 'paypal1@domain.com';
    $email2     = 'paypal2@domain.com';
 
    foreach ( $order->get_items() as $item_id => $item ) {
        if ( has_term( $tag_terms1, 'product_tag', $item->get_product_id() ) ) {
            $paypal_args['business'] = $email1;
            break;
        } elseif ( has_term( $tag_terms2, 'product_tag', $item->get_product_id() ) ) {
            $paypal_args['business'] = $email2;
            break;
        }
    }
    return $paypal_args;
}

// Avoid IPN Failure after switching PayPal email for order items product tags 
require_once WC()->plugin_path() . '/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php';
 
class WC_Gateway_Paypal_IPN_Handler_Switch extends WC_Gateway_Paypal_IPN_Handler { 
    
    protected function validate_receiver_email( $order, $receiver_email ) {
 
        if ( strcasecmp( trim( $receiver_email ), trim( $this->receiver_email ) ) !== 0 ) {
 
            // Here set same paypal emails used above in the array
            if ( ! in_array( $receiver_email array('paypal1@domain.com', 'paypal2@domain.com') ) ) {
 
                WC_Gateway_Paypal::log( "IPN Response is for another account: {$receiver_email}. Your email is {$this->receiver_email}" );
                $order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'woocommerce' ), $receiver_email ) );
                exit;
            }
        }
    }
}
 
new WC_Gateway_Paypal_IPN_Handler_Switch();
代码放在活动子主题(或活动主题)的functions.php文件中。它应该可以工作

重要提示:如果您有一个来自“服装”的订单项目,另一个来自“花园”的订单项目的订单项目的顺序相同,则这将无法按预期工作

相关的:

Error: syntax error, unexpected 'array' (T_ARRAY), expecting ')'
add_filter( 'woocommerce_paypal_args' , 'switch_paypal_email_based_product_tags', 9999, 2 );
function switch_paypal_email_based_product_tags( $paypal_args, $order ) {
    // Here define your product tags
    $tag_terms1 = array('clothing', 'footwear', 'bags'); 
    $tag_terms2 = array('snow', 'sun', 'garden');

    // Here define your emails
    $email1     = 'paypal1@domain.com';
    $email2     = 'paypal2@domain.com';
 
    foreach ( $order->get_items() as $item_id => $item ) {
        if ( has_term( $tag_terms1, 'product_tag', $item->get_product_id() ) ) {
            $paypal_args['business'] = $email1;
            break;
        } elseif ( has_term( $tag_terms2, 'product_tag', $item->get_product_id() ) ) {
            $paypal_args['business'] = $email2;
            break;
        }
    }
    return $paypal_args;
}

// Avoid IPN Failure after switching PayPal email for order items product tags 
require_once WC()->plugin_path() . '/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php';
 
class WC_Gateway_Paypal_IPN_Handler_Switch extends WC_Gateway_Paypal_IPN_Handler { 
    
    protected function validate_receiver_email( $order, $receiver_email ) {
 
        if ( strcasecmp( trim( $receiver_email ), trim( $this->receiver_email ) ) !== 0 ) {
 
            // Here set same paypal emails used above in the array
            if ( ! in_array( $receiver_email array('paypal1@domain.com', 'paypal2@domain.com') ) ) {
 
                WC_Gateway_Paypal::log( "IPN Response is for another account: {$receiver_email}. Your email is {$this->receiver_email}" );
                $order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'woocommerce' ), $receiver_email ) );
                exit;
            }
        }
    }
}
 
new WC_Gateway_Paypal_IPN_Handler_Switch();