选择BACS帐户以显示在WooCommerce的Thankyou页面中 [英] Select BACS account to show in thankyou page in WooCommerce

查看:159
本文介绍了选择BACS帐户以显示在WooCommerce的Thankyou页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WooCommerce商店,其中一个产品可以由多个艺术家进行个性化设置.每个艺术家都有自己的银行帐户来接收付款;因此,我需要显示在谢谢"页面中的银行帐户,并在相应的电子邮件中,是属于所选艺术家的那个帐户.为了确定每个银行帐户和艺术家,我做了下一个:

I have a WooCommerce store in which one product can be personalized by more than one artist. Every artist have their own bank account to receive their payment; so I need the bank account that appears in the thankyou page, and in the corresponding email, be the one belonging to the chosen artist. To identify each bank account and artist, I did the next:

  1. 我为每种产品变型(艺术家)使用the分配了3个字符的标识符.
  2. 我还使用了支付网关中每个银行帐户的分类代码字段来分配相同的3个字符.

现在,我需要找到哪个银行帐户的分类代码等于所选的变化记录account_details[x]['sort_code'] = (the variation slug)

Now, I need to find which bank account have a sort code equal to the selected variation slug account_details[x]['sort_code'] = (the variation slug)

有人可以指出我正确的方向吗?我需要一个循环,以禁用account_details中的所有行,除了那些与变体段匹配的行.

Can someone point me in the right direction? I need a loop that disables all the rows in account_details except for the one that matches the variation slug.

我找到了通过将其与字符串进行比较来选择银行帐户的方法.为此,我在文件class-wc-gateway-bacs.php

I found the way to select the bank account by comparing it to a a string. To do so, I added the condition if ( $bacs_account->sort_code != 'ztc' ) { continue; } in line 255 of the file class-wc-gateway-bacs.php

    foreach ( $bacs_accounts as $bacs_account ) {
        $bacs_account = (object) $bacs_account; if ( $bacs_account->sort_code != 'ztc' ) { continue; }
        if ( $bacs_account->account_name ) {
            $account_html .= '<h3 class="wc-bacs-bank-details-account-name">' . wp_kses_post( wp_unslash( $bacs_account->account_name ) ) . ':</h3>' . PHP_EOL;

但是,我找不到找到变体段将其与$bacs_account->sort_code(而不是字符串)进行比较的方法.另外,我认为最好是使用functions.php文件进行修改,而不要弄乱class-wc-gateway-bacs.php文件.

However, I cant find the way to get the variation slug to compare it to $bacs_account->sort_code (instead of the string). Also, I think it would be better this to be modified by the functions.php file instead of messing with the class-wc-gateway-bacs.php file.

有人可以帮我做任何这件事吗?

Can someone can help me in order to do any of this?

推荐答案

完成!

找到了从https://stackoverflow.com/questions/53009224/get-order-item-meta-data-in-an-unprotected-array-in-woocommerce-3获取变异条的方法.所以我刚刚添加:

Found the way to get the variation slug from https://stackoverflow.com/questions/53009224/get-order-item-meta-data-in-an-unprotected-array-in-woocommerce-3. So I just added:

foreach ( $order->get_items() as $item ) {$sede = $item->get_meta("pa_sede");}; if ( $bacs_account->sort_code != $sede ) { continue; };

foreach ( $order->get_items() as $item ) {$sede = $item->get_meta("pa_sede");}; if ( $bacs_account->sort_code != $sede ) { continue; };

在"class-wc-gateway-bacs.php"文件中的第255行之后.我还注释了第272-275行以隐藏排序代码字段,因为这对于选择帐户很有用,但对用户没有用.

after line 255 in the file "class-wc-gateway-bacs.php". I also commented lines 272-275 to hide the sort code field as it is usefull to select the account, but has no use for the user.

            foreach ( $bacs_accounts as $bacs_account ) {
                $bacs_account = (object) $bacs_account;

    foreach ( $order->get_items() as $item ) {$sede = $item->get_meta("pa_sede");};
    if ( $bacs_account->sort_code != $sede ) { continue; };

                if ( $bacs_account->account_name ) {
                    $account_html .= '<h3 class="wc-bacs-bank-details-account-name">' . wp_kses_post( wp_unslash( $bacs_account->account_name ) ) . ':</h3>' . PHP_EOL;
                }
                $account_html .= '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL;
                // BACS account fields shown on the thanks page and in emails.
                $account_fields = apply_filters(
                    'woocommerce_bacs_account_fields',
                    array(
                        'bank_name'      => array(
                            'label' => __( 'Bank', 'woocommerce' ),
                            'value' => $bacs_account->bank_name,
                        ),
                        'account_number' => array(
                            'label' => __( 'Account number', 'woocommerce' ),
                            'value' => $bacs_account->account_number,
                        ),
//                      'sort_code'      => array(
//                          'label' => $sortcode,
//                          'value' => $bacs_account->sort_code,
//                      ),
                        'iban'           => array(
                            'label' => __( 'IBAN', 'woocommerce' ),
                            'value' => $bacs_account->iban,
                        ),
                        'bic'            => array(
                            'label' => __( 'BIC', 'woocommerce' ),
                            'value' => $bacs_account->bic,
                        ),
                    ),
                    $order_id
                );
                foreach ( $account_fields as $field_key => $field ) {
                    if ( ! empty( $field['value'] ) ) {
                        $account_html .= '<li class="' . esc_attr( $field_key ) . '">' . wp_kses_post( $field['label'] ) . ': <strong>' . wp_kses_post( wptexturize( $field['value'] ) ) . '</strong></li>' . PHP_EOL;
                        $has_details   = true;
                    }
                }
                $account_html .= '</ul>';
            }

一切正常.

这篇关于选择BACS帐户以显示在WooCommerce的Thankyou页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆