【问题标题】:Show Woocommerce custom checkout field value in admin order making them editable以管理员顺序显示 Woocommerce 自定义结帐字段值,使其可编辑
【发布时间】:2019-02-28 18:48:36
【问题描述】:

我正在使用 "Show hide custom WooCommerce checkout field based on selected payment method" 回答我的一个问题,以显示/隐藏自定义结帐结算字段,并且效果很好。

问题:是否可以在管理面板的 WooCommerce 订单中显示我的自定义字段?

【问题讨论】:

    标签: php wordpress woocommerce metadata orders


    【解决方案1】:

    要在账单信息列的管理订单页面中显示“billing_options”自定义结帐账单字段值,请使用以下命令:

    add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_billing_options_value_in_admin_order', 10, 1 );
    function display_billing_options_value_in_admin_order($order){
        if( $value = get_post_meta( $order->get_id(), '_billing_options', true ) )
            echo '<p><strong>'.__('Invoice Number', 'woocommerce').':</strong> ' . $value . '</p>';
    }
    

    要使此自定义结帐结算字段在后端显示为可编辑,请使用以下命令:

    add_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 10, 1 );
    function custom_admin_billing_fields( $fields ) {
        $fields['options'] = array(
            'label' => __('Invoice Number', 'woocommerce'),
            'show'  => true,
        );
        return $fields;
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且有效。

    【讨论】:

      【解决方案2】:
      add_action( 'woocommerce_admin_order_data_after_order_details', 'mycustom_order_meta_general' );
      
      function mycustom_order_meta_general( $order ){  ?>
      
              <br class="clear" />
              <h4>Gift Order <a href="#" class="edit_address">Edit</a></h4>
              <?php 
                  /*
                   * get all the meta data values we need
                   */ 
                  $_mycustomfield = get_post_meta( $order->get_id(), '_mycustomfield', true );
      
              ?>
              <div class="address">
                  <p><strong>My Custom Field</strong></p>
                  <?php
      
                      if( $_mycustomfield ) : 
                      ?>
                          <p><strong>MY custom:</strong> <?php echo $_mycustomfield ?></p>
      
                      <?php
                      endif;
                  ?>
              </div>
      <?php } ?>
      

      【讨论】:

        猜你喜欢
        • 2018-10-01
        • 1970-01-01
        • 2018-02-22
        • 2020-08-14
        • 1970-01-01
        • 2023-03-27
        • 2021-04-12
        • 1970-01-01
        • 2019-04-14
        相关资源
        最近更新 更多