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

僅在手動訂單的 WooCommerce 管理單個訂單中顯示產(chǎn)

Display a product custom field only in WooCommerce Admin single orders for Manual Orders(僅在手動訂單的 WooCommerce 管理單個訂單中顯示產(chǎn)品自定義字段)
本文介紹了僅在手動訂單的 WooCommerce 管理單個訂單中顯示產(chǎn)品自定義字段的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

以下 僅顯示產(chǎn)品自定義字段在 WooCommerce 管理單一訂單中 回答我之前的問題,其中:

Following Display a product custom field only in WooCommerce Admin single orders answer to my previous question, which:

  1. 添加自定義 SKU 字段(文章 ID)
  2. 將自定義 SKU(ArticleID)保存為隱藏訂單項元數(shù)據(jù)
  3. 將自定義 SKU(商品 ID)保存為手動訂單的隱藏訂單項元數(shù)據(jù)

但是,似乎最后一部分(對于手動訂單)與以下我為網(wǎng)關(guān)費用添加的其他自定義代碼發(fā)生沖突:

However, it seems that the last part (for Manual Orders) is causing a conflict with this following other custom code I added for Gateway Fees:

// Assign Card Gateway Percentage Fee to Wholesaler Profiles
add_action('woocommerce_cart_calculate_fees', 'sm_credit_card_fee_role_gateway' );
function sm_credit_card_fee_role_gateway( $cart ){
    if ( is_admin() && !defined('DOING_AJAX') )
        return;

    // Only on checkout page and logged in users
    if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) || ! is_user_logged_in() )
        return;

    $wpuser_object = wp_get_current_user();
    $allowed_roles = array('administrator', 'default_wholesaler', 'wholesaler-non-vat-registered', 'wholesaler-ex-vat-registered', 'wholesaler-ex-non-vat-registered', 'shop_manager');

    if ( array_intersect($allowed_roles, $wpuser_object->roles) ){
        $payment_method = WC()->session->get('chosen_payment_method');

        if ( 'cardgatecreditcard' === $payment_method ){
            $percentage = 8.25;
            $description = 'Credit Card';
        }
        elseif ( 'cardgatesofortbanking' === $payment_method ){
            $percentage = 6;
            $description = 'SofortBanking';
        }
        elseif ( 'cardgategiropay' === $payment_method ){
            $percentage = 3.15;
            $description = 'GiroPay';
        }
        elseif ( 'cardgateideal' === $payment_method ){
            $percentage = 2.1;
            $description = 'iDEAL';
        }
    }
    if ( isset($percentage) ) {
        $surcharge = ($cart->cart_contents_total + $cart->shipping_total) * $percentage / 100;
        $cart->add_fee( sprintf( __('%s Fee (%s)', 'woocommerce'), $description, $percentage . '%' ), $surcharge, true );
    }
}

當我嘗試更新或更改應(yīng)用了網(wǎng)關(guān)費用的訂單的狀態(tài)時,我收到此致命錯誤:

When I try to update or change the status of an order that has Gateway Fees applied to it, I get this Fatal Error:

所以要么我的 SKU 代碼的第 3 部分需要編寫得更好,要么我的網(wǎng)關(guān)費用代碼需要更新.我該如何進一步解決此問題?

So either part 3 of my SKU code needs to be written better, or my gateway fee code needs to be updated. How do I go about troubleshooting this further?

這是致命錯誤:

Fatal error: Uncaught Error: Call to undefined method WC_Order_Item_Fee::get_product() in …/public_html/wp-content/themes/oceanwp-child/functions.php:920 
Stack trace: 
#0 …/public_html/wp-includes/class-wp-hook.php(287): action_before_save_order_item_callback(Object(WC_Order_Item_Fee)) 
#1 …/public_html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array) 
#2 …/public_html/wp-includes/plugin.php(478): WP_Hook->do_action(Array) 
#3 …/public_html/wp-content/plugins/woocommerce/includes/admin/wc-admin-functions.php(324): do_action('woocommerce_bef...', Object(WC_Order_Item_Fee)) 
#4 …/public_html/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-items.php(54): wc_save_order_items(6053, Array) 
#5 …/public_html/wp-includes/class-wp-hook.php(289): WC_Meta_B in …/public_html/wp-content/themes/oceanwp-child/functions.php on line 920

第 920 行是Save SKU"ArticleID"的一部分作為手動訂單的隱藏訂單項元數(shù)據(jù)":

The line Line 920 which is part of "Save SKU "ArticleID" as Hidden Order Item Meta Data for Manual Orders":

$product = $item->get_product(); // Get the WC_Product Object

推薦答案

您只需要定位最后一個函數(shù)上的行項目,這樣:

You need to target only line items on the last function, this way:

add_action( 'woocommerce_before_save_order_item', 'action_before_save_order_item_callback' );
function action_before_save_order_item_callback( $item ) {
    // Targeting only order item type "line_item"
    if ( $item->get_type() !== 'line_item' )
        return; // exit

    $articleid = $item->get_meta('articleid');

    if ( ! $articleid ) {
        $product = $item->get_product(); // Get the WC_Product Object
        
        // Get custom meta data from the product
        $articleid = $product->get_meta('articleid');
        
        // For product variations when the "articleid" is not defined
        if ( ! $articleid && $item->get_variation_id() > 0 ) {
            $product   = wc_get_product( $item->get_product_id() ); // Get the parent variable product
            $articleid = $product->get_meta( 'articleid' );  // Get parent product "articleid"
        }

        // Save it as custom order item (if defined for the product)        
        if ( $articleid ) {
            $item->update_meta_data( '_articleid', $articleid );
        }
    }
}

代碼位于活動子主題(或活動主題)的functions.php 文件中.現(xiàn)在應(yīng)該可以使用了.

Code goes in functions.php file of the active child theme (or active theme). It should works now.

與此線程相關(guān):

  • 更改訂單項顯示元WooCommerce 管理訂單頁面中的關(guān)鍵標簽
  • 僅在WooCommerce 管理員單個訂單
  • 更改訂單項顯示元WooCommerce 管理訂單頁面中的關(guān)鍵標簽

這篇關(guān)于僅在手動訂單的 WooCommerce 管理單個訂單中顯示產(chǎn)品自定義字段的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
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 簡單產(chǎn)品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 日韩在线欧美 | 麻豆av在线| 日韩欧美黄色 | 国产精品自在线 | 日韩欧美视频在线 | 一区二区在线 | 四虎午夜剧场 | 亚洲精品在线观看视频 | 777777777亚洲妇女 | 日韩av手机在线观看 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 天天操天天摸天天干 | 亚洲激情专区 | 日韩视频一区在线观看 | 偷偷操视频| 久久99久久 | 国产农村妇女毛片精品久久麻豆 | 91视频免费视频 | 一二三区视频 | 国产资源在线播放 | 国产激情片在线观看 | 伊人久久免费 | 午夜精品视频一区 | av在线播放网 | 国产精品美女久久久久aⅴ国产馆 | 日本不卡一区 | 91欧美精品成人综合在线观看 | 国产成人精品区一区二区不卡 | 日本午夜网 | 一级国产精品一级国产精品片 | 色影视| 一级a爱片久久毛片 | 午夜在线视频 | 一区二区三区影院 | 中文字幕在线看第二 | 精品不卡 | 国产欧美在线播放 | 欧美精品一区二区三区在线 | 91久久综合亚洲鲁鲁五月天 | 黄色一级视频 | 国产h视频 |