pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

僅在手動訂單的 WooCommerce 管理單個訂單中顯示產

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

問題描述

限時送ChatGPT賬號..

以下 僅顯示產品自定義字段在 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)保存為隱藏訂單項元數據
  3. 將自定義 SKU(商品 ID)保存為手動訂單的隱藏訂單項元數據

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

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 );
    }
}

當我嘗試更新或更改應用了網關費用的訂單的狀態時,我收到此致命錯誤:

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 部分需要編寫得更好,要么我的網關費用代碼需要更新.我該如何進一步解決此問題?

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"的一部分作為手動訂單的隱藏訂單項元數據":

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

推薦答案

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

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 文件中.現在應該可以使用了.

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

與此線程相關:

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

這篇關于僅在手動訂單的 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)
主站蜘蛛池模板: 吲哚菁绿衍生物-酶底物法大肠菌群检测试剂-北京和信同通科技发展有限公司 | 细砂提取机,隔膜板框泥浆污泥压滤机,螺旋洗砂机设备,轮式洗砂机械,机制砂,圆锥颚式反击式破碎机,振动筛,滚筒筛,喂料机- 上海重睿环保设备有限公司 | 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | 博客-悦享汽车品质生活| 次氯酸钠厂家,涉水级次氯酸钠,三氯化铁生产厂家-淄博吉灿化工 | 不锈钢水管-不锈钢燃气管-卫生级不锈钢管件-不锈钢食品级水管-广东双兴新材料集团有限公司 | 除甲醛公司-甲醛检测-广西雅居环境科技有限公司 | 动物麻醉机-数显脑立体定位仪-北京易则佳科技有限公司 | 医用空气消毒机-医用管路消毒机-工作服消毒柜-成都三康王 | 铝扣板-铝方通-铝格栅-铝条扣板-铝单板幕墙-佳得利吊顶天花厂家 elisa试剂盒价格-酶联免疫试剂盒-猪elisa试剂盒-上海恒远生物科技有限公司 | 精密冲床,高速冲床等冲压设备生产商-常州晋志德压力机厂 | 隔离变压器-伺服变压器--输入输出电抗器-深圳市德而沃电气有限公司 | 山楂片_雪花_迷你山楂片_山楂条饼厂家-青州市丰源食品厂 | 包装设计公司,产品包装设计|包装制作,包装盒定制厂家-汇包装【官方网站】 | 锯边机,自动锯边机,双面涂胶机-建业顺达机械有限公司 | 液晶拼接屏厂家_拼接屏品牌_拼接屏价格_监控大屏—北京维康 | 外贸网站建设-外贸网站设计制作开发公司-外贸独立站建设【企术】 | 不锈钢螺丝 - 六角螺丝厂家 - 不锈钢紧固件 - 万千紧固件--紧固件一站式采购 | 防火卷帘门价格-聊城一维工贸特级防火卷帘门厂家▲ | 电动球阀_不锈钢电动球阀_电动三通球阀_电动调节球阀_上海湖泉阀门有限公司 | 【ph计】|在线ph计|工业ph计|ph计厂家|ph计价格|酸度计生产厂家_武汉吉尔德科技有限公司 | 衬四氟_衬氟储罐_四氟储罐-无锡市氟瑞特防腐科技有限公司 | 信阳网站建设专家-信阳时代网联-【信阳网站建设百度推广优质服务提供商】信阳网站建设|信阳网络公司|信阳网络营销推广 | 定量包装机,颗粒定量包装机,粉剂定量包装机,背封颗粒包装机,定量灌装机-上海铸衡电子科技有限公司 | 纯水电导率测定仪-万用气体检测仪-低钠测定仪-米沃奇科技(北京)有限公司www.milwaukeeinst.cn 锂辉石检测仪器,水泥成分快速分析仪-湘潭宇科分析仪器有限公司 手术室净化装修-手术室净化工程公司-华锐手术室净化厂家 | 上海地磅秤|电子地上衡|防爆地磅_上海地磅秤厂家–越衡称重 | 接地电阻测试仪[厂家直销]_电缆故障测试仪[精准定位]_耐压测试仪-武汉南电至诚电力设备 | 冷水机,风冷冷水机,水冷冷水机,螺杆冷水机专业制造商-上海祝松机械有限公司 | 线粒体膜电位荧光探针-细胞膜-标记二抗-上海复申生物科技有限公司 | 安全阀_弹簧式安全阀_美标安全阀_工业冷冻安全阀厂家-中国·阿司米阀门有限公司 | 硫化罐_蒸汽硫化罐_大型硫化罐-山东鑫泰鑫智能装备有限公司 | 2025世界机器人大会_IC China_半导体展_集成电路博览会_智能制造展览网 | 丙烷/液氧/液氮气化器,丙烷/液氧/液氮汽化器-无锡舍勒能源科技有限公司 | 上海恒驭仪器有限公司-实验室平板硫化机-小型平板硫化机-全自动平板硫化机 | 滤芯,过滤器,滤油机,贺德克滤芯,精密滤芯_新乡市宇清流体净化技术有限公司 | 丝杆升降机-不锈钢丝杆升降机-非标定制丝杆升降机厂家-山东鑫光减速机有限公司 | 口信网(kousing.com) - 行业资讯_行业展会_行业培训_行业资料 | 主题班会网 - 安全教育主题班会,各类主题班会PPT模板 | 辽宁资质代办_辽宁建筑资质办理_辽宁建筑资质延期升级_辽宁中杭资质代办 | 合肥弱电工程_安徽安防工程_智能化工程公司-合肥雷润 | 阿尔法-MDR2000无转子硫化仪-STM566 SATRA拉力试验机-青岛阿尔法仪器有限公司 |