久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Woocommerce 中隨處保存和顯示特定的支付網關附

Save and display specific payment gateway additional field everywhere in Woocommerce(在 Woocommerce 中隨處保存和顯示特定的支付網關附加字段)
本文介紹了在 Woocommerce 中隨處保存和顯示特定的支付網關附加字段的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在使用 "

<小時>

在收到訂單頁面(在訂單視圖和電子郵件通知上):

<小時>

在管理訂單頁面:

I am using "Additional field on checkout for specific payment gateway in Woocommerce" answer code, that displays an additional dropdown field for specific payment gateway in checkout page.

How to save and display the options on the orders and on email notifications?

解決方案

Continuation of "Additional field on checkout for specific payment gateway in Woocommerce"

Here is the complete way to:

  1. Add a dropdown with options to BACS payment
  2. Field validation (required option)
  3. Save chosen option as order custom meta data
  4. Display the chosen option on order totals everywhere (orders and emails notifications)
  5. Display the chosen option on admin order edit page below billing details.

The code:

// BACS payement gateway description: Append custom select field
add_filter( 'woocommerce_gateway_description', 'gateway_bacs_custom_fields', 20, 2 );
function gateway_bacs_custom_fields( $description, $payment_id ){
    //
    if( 'bacs' === $payment_id ){
        ob_start(); // Start buffering

        echo '<div  class="bacs-options" style="padding:10px 0;">';

        woocommerce_form_field( 'bacs_option', array(
            'type'          => 'select',
            'label'         => __("Fill in this field", "woocommerce"),
            'class'         => array('form-row-wide'),
            'required'      => true,
            'options'       => array(
                ''          => __("Select something", "woocommerce"),
                'Option 1'  => __("Choice one", "woocommerce"),
                'Option 2'  => __("Choice two", "woocommerce"),
            ),
        ), '');

        echo '<div>';

        $description .= ob_get_clean(); // Append buffered content
    }
    return $description;
}

// Checkout custom field validation
add_action('woocommerce_checkout_process', 'bacs_option_validation' );
function bacs_option_validation() {
    if ( isset($_POST['payment_method']) && $_POST['payment_method'] === 'bacs'
    && isset($_POST['bacs_option']) && empty($_POST['bacs_option']) ) {
        wc_add_notice( __( 'Please Select an option for "Direct Bank Transfer" payment, please.' ), 'error' );
    }
}

// Checkout custom field save to order meta
add_action('woocommerce_checkout_create_order', 'save_bacs_option_order_meta', 10, 2 );
function save_bacs_option_order_meta( $order, $data ) {
    if ( isset($_POST['bacs_option']) && ! empty($_POST['bacs_option']) ) {
        $order->update_meta_data( '_bacs_option' , esc_attr($_POST['bacs_option']) );
    }
}

// Display custom field on order totals lines everywhere
add_action('woocommerce_get_order_item_totals', 'display_bacs_option_on_order_totals', 10, 3 );
function display_bacs_option_on_order_totals( $total_rows, $order, $tax_display ) {
    if ( $order->get_payment_method() === 'bacs' && $bacs_option = $order->get_meta('_bacs_option') ) {
        $sorted_total_rows = [];

        foreach ( $total_rows as $key_row => $total_row ) {
            $sorted_total_rows[$key_row] = $total_row;
            if( $key_row === 'payment_method' ) {
                $sorted_total_rows['bacs_option'] = [
                    'label' => __( "Bank wire option", "woocommerce"),
                    'value' => esc_html( $bacs_option ),
                ];
            }
        }
        $total_rows = $sorted_total_rows;
    }
    return $total_rows;
}

// Display custom field in Admin orders, below billing address block
add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_bacs_option_near_admin_order_billing_address', 10, 1 );
function display_bacs_option_near_admin_order_billing_address( $order ){
    if( $bacs_option = $order->get_meta('_bacs_option') ) {
        echo '<div class="bacs-option">
        <p><strong>'.__('BACS option').':</strong> ' . $bacs_option . '</p>
        </div>';
    }
}

Code goes in functions.php file of your active child theme (or active theme). tested and works.

On checkout page:


On Order received page (on Order view and email notifications):


On Admin Order pages:

這篇關于在 Woocommerce 中隨處保存和顯示特定的支付網關附加字段的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 久久这里只有精品首页 | 日日摸夜夜爽人人添av | 亚洲精品日韩视频 | 亚洲第一av | 欧美激情久久久 | 男女视频在线观看免费 | 日韩一区二区三区在线 | 一区中文字幕 | 福利一区视频 | 精品久久国产 | 日日夜夜91 | 国产精品夜间视频香蕉 | 亚洲国产成人精品在线 | 麻豆久久 | 日韩欧美三区 | 精品一区二区三区中文字幕 | 在线视频h| 天天影视色综合 | 综合激情av | 亚洲精品日韩在线 | 久久精品伊人 | 亚洲国产精品一区二区第一页 | 女同av亚洲女人天堂 | 午夜成人免费视频 | 超碰超碰| 91精品国产色综合久久 | 日本成人毛片 | 超碰97人人人人人蜜桃 | 一级黄a视频 | 日本在线免费观看 | 亚洲日本欧美日韩高观看 | 国产日韩在线观看一区 | 日日夜夜影院 | 亚洲精选久久 | 中文字幕欧美在线观看 | 午夜综合 | 亚洲成人高清 | 欧美爱爱视频 | 草草草久久久 | 日韩在线视频免费观看 | 中文字幕在线视频免费观看 |