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

如何獲得 WooCommerce 運輸方式的成本和設置?

How to get WooCommerce shipping methods cost and settings?(如何獲得 WooCommerce 運輸方式的成本和設置?)
本文介紹了如何獲得 WooCommerce 運輸方式的成本和設置?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試獲取所有運輸方式及其費率和標題.但是當我使用 WC()->shipping->get_shipping_methods() 時,它只會返回空的費率數組和空的標題字符串.這是一個轉儲:

I'm trying to get all shipping methods, with their rates and title. But when i use WC()->shipping->get_shipping_methods() it will only return empty rates array, and empty title string. Here is a dump:

     array (size=3)
  'flat_rate' => 
    object(WC_Shipping_Flat_Rate)[1861]
      protected 'fee_cost' => string '' (length=0)
      public 'supports' => 
        array (size=3)
          0 => string 'shipping-zones' (length=14)
          1 => string 'instance-settings' (length=17)
          2 => string 'instance-settings-modal' (length=23)
      public 'id' => string 'flat_rate' (length=9)
      public 'method_title' => string 'Flat rate' (length=9)
      public 'method_description' => string 'Lets you charge a fixed rate for shipping.' (length=42)
      public 'enabled' => string 'yes' (length=3)
      public 'title' => string '' (length=0)
      public 'rates' => 
        array (size=0)
          empty
      public 'tax_status' => string '' (length=0)
      public 'fee' => null
      public 'minimum_fee' => null
      public 'instance_id' => int 0
      public 'instance_form_fields' => 
        array (size=3)
          'title' => 
            array (size=5)
              ...
          'tax_status' => 
            array (size=5)
              ...
          'cost' => 
            array (size=7)
              ...
      public 'instance_settings' => 
        array (size=0)
          empty
      public 'availability' => null
      public 'countries' => 
        array (size=0)
          empty
      public 'plugin_id' => string 'woocommerce_' (length=12)
      public 'errors' => 
        array (size=0)
          empty
      public 'settings' => 
        array (size=4)
          'title' => string '' (length=0)
          'tax_status' => string '' (length=0)
          'cost' => string '' (length=0)
          'type' => string 'class' (length=5)
      public 'form_fields' => 
        array (size=0)
          empty
      protected 'data' => 
        array (size=0)
          empty
      public 'cost' => string '' (length=0)
      public 'type' => string 'class' (length=5)

我試圖用谷歌搜索這個問題,但沒有任何幫助.有誰知道可能是什么問題?

I tried to Google the issue, but nothing really helped. Does anyone know what could be the issue?

非常感謝!

推薦答案

因為 WC()->shipping->get_shipping_methods() 不會加載在每個運輸區域,它只加載您可以在任何運輸區域設置的所有可用運輸方式,以及所有默認值和可用的設置字段......

Because WC()->shipping->get_shipping_methods() doesn't load the shipping methods that are set on each shipping zone, it just loads all available shipping methods that you can set in any shipping zone, with all default values and available fields for settings…

請記住,運輸方式成本和設置按運輸區域設置,并且與位置(地區、國家/地區、州或郵政編碼)相關.

Remember that shipping methods costs and settings are set by shipping zone and are related to locations (Region, country, state or postcode).

因此,由于每個送貨區域的送貨方式費率不同,您需要首先獲得在送貨部分設置中設置的一個或所有送貨區域.

So as shipping methods rates are different for each shipping zone you need to get first, one or all shipping Zones that are set in shipping section settings.

然后,您可以從運輸區域獲得為其設置的所有運輸方式費率,例如:

Then from a shipping zone you can get all shipping methods rates that is set for it like:

// Get all your existing shipping zones IDS
$zone_ids = array_keys( array('') + WC_Shipping_Zones::get_zones() );

// Loop through shipping Zones IDs
foreach ( $zone_ids as $zone_id ) 
{
    // Get the shipping Zone object
    $shipping_zone = new WC_Shipping_Zone($zone_id);

    // Get all shipping method values for the shipping zone
    $shipping_methods = $shipping_zone->get_shipping_methods( true, 'values' );

    // Loop through each shipping methods set for the current shipping zone
    foreach ( $shipping_methods as $instance_id => $shipping_method ) 
    {
        // The dump of protected data from the current shipping method
        var_dump($shipping_method);
    }
}

這一次,正如您將看到的,您將獲得在配送區域中設置的每種配送方式費率的所有設置(自定義標簽、成本和其他設置).

This time, as you will see, you get all settings (custom label, costs and other settings) for each shipping method rate set in a shipping zone.

這篇關于如何獲得 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)
主站蜘蛛池模板: 盘煤仪,盘料仪,盘点仪,堆料测量仪,便携式激光盘煤仪-中科航宇(北京)自动化工程技术有限公司 | 全自动面膜机_面膜折叠机价格_面膜灌装机定制_高速折棉机厂家-深圳市益豪科技有限公司 | 阿米巴企业经营-阿米巴咨询管理-阿米巴企业培训-广东键锋企业管理咨询有限公司 | 造价工程师网,考试时间查询,报名入口信息-网站首页 | 硫化罐_蒸汽硫化罐_大型硫化罐-山东鑫泰鑫智能装备有限公司 | 外观设计_设备外观设计_外观设计公司_产品外观设计_机械设备外观设计_东莞工业设计公司-意品深蓝 | 首页 - 军军小站|张军博客 | 考试试题_试卷及答案_诗词单词成语 - 优易学 | 中药二氧化硫测定仪,食品二氧化硫测定仪|俊腾百科 | 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 广东护栏厂家-广州护栏网厂家-广东省安麦斯交通设施有限公司 | YT保温材料_YT无机保温砂浆_外墙保温材料_南阳银通节能建材高新技术开发有限公司 | 家乐事净水器官网-净水器厂家「官方」 | 阻垢剂-反渗透缓蚀阻垢剂厂家-山东鲁东环保科技有限公司 | 环氧树脂地坪漆_济宁市新天地漆业有限公司 | 政府园区专业委托招商平台_助力企业选址项目快速落地_东方龙商务集团 | ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 数控专用机床,专用机床,自动线,组合机床,动力头,自动化加工生产线,江苏海鑫机床有限公司 | LZ-373测厚仪-华瑞VOC气体检测仪-个人有毒气体检测仪-厂家-深圳市深博瑞仪器仪表有限公司 | 国际线缆连接网 - 连接器_线缆线束加工行业门户网站 | 颗粒机,颗粒机组,木屑颗粒机-济南劲能机械有限公司 | 滚珠丝杆升降机_螺旋升降机_丝杠升降机-德迈传动 | 北京发电车出租-发电机租赁公司-柴油发电机厂家 - 北京明旺盛安机电设备有限公司 | IPO咨询公司-IPO上市服务-细分市场研究-龙马咨询 | 网站制作优化_网站SEO推广解决方案-无锡首宸信息科技公司 | 精密线材测试仪-电线电缆检测仪-苏州欣硕电子科技有限公司 | 流程管理|流程管理软件|企业流程管理|微宏科技-AlphaFlow_流程管理系统软件服务商 | 中医中药治疗血小板减少-石家庄血液病肿瘤门诊部 | 浙江上沪阀门有限公司 | 珠宝展柜-玻璃精品展柜-首饰珠宝展示柜定制-鸿钛展柜厂家 | 深圳市宏康仪器科技有限公司-模拟高空低压试验箱-高温防爆试验箱-温控短路试验箱【官网】 | 北京四合院出租,北京四合院出售,北京平房买卖 - 顺益兴四合院 | 安徽合肥格力空调专卖店_格力中央空调_格力空调总经销公司代理-皖格制冷设备 | 泥浆在线密度计厂家-防爆数字压力表-膜盒-远传压力表厂家-江苏大亚自控设备有限公司 | 上海皓越真空设备有限公司官网-真空炉-真空热压烧结炉-sps放电等离子烧结炉 | 成都装修公司-成都装修设计公司推荐-成都朗煜装饰公司 | 成都顶呱呱信息技术有限公司-贷款_个人贷款_银行贷款在线申请 - 成都贷款公司 | 砍排机-锯骨机-冻肉切丁机-熟肉切片机-预制菜生产线一站式服务厂商 - 广州市祥九瑞盈机械设备有限公司 | 雨水收集系统厂家-雨水收集利用-模块雨水收集池-徐州博智环保科技有限公司 | 除甲醛公司-甲醛检测治理-杭州创绿家环保科技有限公司-室内空气净化十大品牌 | 元拓建材集团官方网站|