duanlie4621 2018-10-25 09:04
浏览 66

将作者电子邮件地址附加到paypal的产品 - 代码已停止工作

The following code has been working beautifully for my Woocommerce Wordpress website, but after the most recent update it has stopped working.

Anyone have any insight into what may be causing the code to stop working?

Any insight or help will be such big help as this is a key feature of my site.

Thanks!

===================================================================
     *
     * Function to enable item-specific paypal email addresses
     *
     * ================================================================ */
    function find_alt_paypal_emails() {
        global $woocommerce;
        // loop over the items in the cart
        foreach ( $woocommerce->cart->cart_contents as $item ) {
            // check to see if any of them has the 'paypal_email' meta value
            $override_email = get_post_meta($item['product_id'], 'paypal_email', true);
            // if there is an override val, build an array of each item name and the
            // paypal email associated with that item
            if ( ! empty( $override_email ) ) {
                $paypal_override = array(
                    'item_title' => $item['data']->post->post_title,
                    'email' => $override_email
                    );
                $paypal_overrides[] = $paypal_override;
                // error_log(print_r($paypal_overrides,true));
            }
        }
        // if there are override emails indicated
        if ( ! empty( $paypal_overrides ) ) {
            // loop through and build an error message to warn the user of multiple payees
            if ( count( $paypal_overrides ) > 1 ) {
                $error_list = '';
                foreach ( $paypal_overrides as $override ) {
                    $error_list .= $override['item_title'] . ' → ' . $override['email'] . ', ';
                }
                $error_list = rtrim($error_list, ', ');
                $woocommerce->add_error( __( 'The following items send payment to different '
                    . 'PayPal Users, please place separate orders: (' . $error_list . ')', 'woocommerce' ) );
            } else {
                return $paypal_overrides[0]['email'];
            }
        }
    }
    add_action( 'woocommerce_after_cart_contents', 'find_alt_paypal_emails' );
    add_action( 'woocommerce_after_checkout_form', 'find_alt_paypal_emails' );
    add_action( 'woocommerce_after_order_total', 'find_alt_paypal_emails' );
    /*$paypal_args = apply_filters( 'woocommerce_paypal_args', $paypal_args );*/
    // Hook in
    add_filter( 'woocommerce_paypal_args' , 'custom_override_paypal_email' );
    // Our hooked in function is passed via the filter!
    function custom_override_paypal_email( $paypal_args ) {
        $alt_email = find_alt_paypal_emails();
        error_log(print_r($alt_email,true));
        if ( empty( $alt_email ) ) {
            return $paypal_args;
        }
        $paypal_args['business'] = find_alt_paypal_emails();
        print_r( $paypal_args['business'],true );
        return $paypal_args;
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?