【问题标题】:Output a product custom field in WooCommerce Order Admin Page (ACF)在 WooCommerce 订单管理页面 (ACF) 中输出产品自定义字段
【发布时间】:2017-12-13 13:23:40
【问题描述】:

使用 WooCommerce,我使用 Advanced Custom Fields plugin 来跟踪我实际存储每个产品的位置。

收到订单后,我希望能够查看管理员编辑订单页面并查看商品的存储位置。所以我可以抓住它来运送。

这是我想看的图片:

希望这是有道理的。

我只想在 Wordpress 的编辑订单管理页面上为每个产品调用单个产品 ACF 变量 (BinLocation)。有什么帮助吗?

谢谢。

【问题讨论】:

    标签: php wordpress woocommerce advanced-custom-fields orders


    【解决方案1】:

    更新:使用 woocommerce_before_order_itemmeta 动作挂钩中的自定义函数,您将能够实现您想要的:

    add_action( 'woocommerce_before_order_itemmeta', 'storage_location_of_order_items', 10, 3 );
    function storage_location_of_order_items( $item_id, $item, $product ){
        // Only on backend order edit pages
        if( ! ( is_admin() && $item->is_type('line_item') ) ) return;
    
        // Get your ACF product value (replace the slug by yours below)
        if( $acf_value = get_field( 'BinLocation', $product->get_id() ) ) {
            $acf_label = __('Stored in: ');
    
            // Outputing the value of the "location storage" for this product item
            echo '<div class="wc-order-item-custom"><strong>' . $acf_value .  $acf_label . '</strong></div>';
        }
    }
    

    代码进入您活动的子主题(或主题)的任何 php 文件或任何插件 php 文件中。

    此代码经过测试,可在 WooCommerce 版本 3 及更高版本中运行……


    【讨论】:

    • 您好,在 wc 3.5 中这似乎不起作用,它显示该字段,但随后停止呈现其余的订单信息、运输和总计?有什么想法吗?
    猜你喜欢
    • 2014-11-14
    • 2021-06-26
    • 2019-06-21
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    相关资源
    最近更新 更多