简体   繁体   English

如何在“我的帐户”页面的“WooCommerce 我的订单”列表中添加自定义数据作为新列?

[英]How to Add Custom Data as a New Column in the WooCommerce My Orders list in My Account page?

I am trying to add 1 column to WooCommerce > My Account > Order Page.我正在尝试将 1 列添加到 WooCommerce > 我的帐户 > 订单页面。

With Jet-Engine I added a field called "url-from-download" inside the Customer Order in WooCommerce.使用 Jet-Engine,我在 WooCommerce 的客户订单中添加了一个名为“url-from-download”的字段。

There inside the customer order I select the PDF.里面有客户订单我select PDF。

The code below adds the Invoice column , and a Text called "Downloads" , but it cannot extract the File as a url for me to download.下面的代码添加了发票列和一个名为“下载”的文本,但它无法将文件提取为 url 供我下载。

Where I'm I getting it wrong??我哪里弄错了??

/**
 * Adds a new column to the "My Orders" table in the account.
 *
 * @param string[] $columns the columns in the orders table
 * @return string[] updated columns
 */
function th_wc_add_my_account_orders_column( $columns ) {

    $new_columns = array();

    foreach ( $columns as $key => $name ) {

        $new_columns[ $key ] = $name;

        // add ship-to after order status column
        if ( 'order-total' === $key ) {
            $new_columns['url-from-download'] = __( 'Invoice', 'textdomain' );
        }
    }

    return $new_columns;
}
add_filter( 'woocommerce_my_account_my_orders_columns', 'th_wc_add_my_account_orders_column' );

/**
 * Adds data to the custom "url-from-download" column in "My Account > Orders".
 *
 * @param \WC_Order $order the order object for the row
 */
function th_wc_my_orders_url_from_download_column( $order ) {

    $url_from_download = get_post_meta( $order->get_id(), 'url_from_download', true ); // Get custom order meta
    echo ! empty( $url_from_download ) ? $url_from_download : 'Download';
    
}
add_action( 'woocommerce_my_account_my_orders_column_url-from-download', 'th_wc_my_orders_url_from_download_column' ); 

I added a field called "url-from-download"我添加了一个名为“url-from-download”的字段

you have stated in question that your field is called url-from-download but in your code, you're using url_from_download您有疑问地表示您的字段名为url-from-download但在您的代码中,您使用的是url_from_download

There is a difference in dash (-) & underscore (_) so make sure you're using the correct meta key in get_post_meta破折号 (-) 和下划线 (_) 有所不同,因此请确保您在get_post_meta中使用了正确的元键

UPDATE更新

as per the discussion, I am assuming you're getting the url but you need it as button style that you can click.根据讨论,我假设你得到 url 但你需要它作为你可以点击的按钮样式。

To do that you need to add <a> tag in your code, the code will be like this.为此,您需要在代码中添加<a>标记,代码将如下所示。

Replace echo? empty( $url_from_download ): $url_from_download; 'Download';替换echo? empty( $url_from_download ): $url_from_download; 'Download'; echo? empty( $url_from_download ): $url_from_download; 'Download'; line with below code符合以下代码

echo ! empty( $url_from_download ) ? '<a class="button" href=" ' . esc_url($url_from_download) . ' ">Download</a>' : '';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WooCommerce 我的账户订单自定义栏目中添加“支付订单”按钮 - Add “Pay for order” Button in WooCommerce My account Orders Custom Column 在 Woocommerce 中为我的帐户订单表添加自定义列 3+ - Add a custom column to My Account Orders table in Woocommerce 3+ 在 Woocommerce 我的帐户订单的新列中显示产品名称和数量 - Show products name and quantity in a new column on Woocommerce My account Orders 向 Woocommerce 添加在新窗口中打开的我的帐户订单的操作按钮 - Add an action button to Woocommerce my account orders that open in a new window WooCommerce“我的账户”订单表添加多个自定义列 - Add multiple custom columns to WooCommerce "My account" orders table 将列总订单重量添加到 WooCommerce 我的帐户订单 - Add column total order weight to WooCommerce My account Orders 在Woocommerce中每页自定义我的帐户订单列表帖子 - Customizing My Account Orders list post per page in Woocommerce 删除我的帐户订单列表中的分页,使其成为woocommerce中的一个页面 - Remove pagination on My account orders list to make it one page in woocommerce 如何在 WooCommerce“我的帐户”订单表的新列中显示产品名称 - How to show product name in a new column in WooCommerce "My account" orders table 如何在Woocommerce我的帐户边栏中添加新的自定义标题? - How to add new Custom Title in Woocommerce My Account sidebar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM