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条回答

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?