在 WooCommerce 管理员订单列表中添加带有付款 url 的自定义列

Add custom column with payment url on WooCommerce admin orders list

我想在 WooCommerce 管理员订单列表中添加额外的付款列 url

urlis/look像这样:

https://mydomaindotcom/checkout/order-pay/17822/?key=wc_order_w4Z53iHEeYPnq

我的意思是此线程已结束:


这是我的代码尝试:

add_filter( 'manage_edit-shop_order_columns','hbm_order_key_column');
function hbm_order_key_column($columns)
{
    // now it is time to add a custom one
    $columns['wc_order'] = "Link Pay Order";
    return $columns;    
}

还有这个

add_action( 'manage_shop_order_posts_custom_column' , 'your_function_name2' );
function your_function_name2( $column ) {
    global $the_order; // you can use the global WP_Order object here
    // global $post; // is also available here

    if( $column == 'custom_column' ) {

        add_action( 'manage_shop_order_posts_custom_column' , 'your_function_name2' );
function your_function_name2( $column ) {
    global $the_order; // you can use the global WP_Order object here
    // global $post; // is also available here

    if( $column == 'custom_column' ) {
    
    //get this form other thread
    $order = wc_get_order($order_id);
    $pay_now_url = esc_url( $order->get_checkout_payment_url() );
    echo $pay_now_url;
    //http://example.com/checkout/order-pay/{order_id}?pay_for_order=true&key={order_key}
    //http://example.com will be site_url and protocol will depending upon SSL checkout WooCommerce setting.
    }

}


    }

}

遗憾的是没有得到想要的结果。有什么建议吗?

看来您混淆了前端和后端。您所指的url包含几个答案。

  • 包括向“我的帐户”订单添加一列的代码table(前端)
  • 以及在 WooCommerce 管理员订单列表(后端)上添加一列的代码

根据您的代码尝试,您将希望在后端添加一列, 这可以通过以下方式完成:

// Display on order admin list (header)
function filter_manage_edit_shop_order_columns( $columns ) {
    // Add columns
    $columns['order_payment_url'] = __( 'Link Pay Order', 'woocommerce' );

    return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'filter_manage_edit_shop_order_columns', 10, 1 );

// Display details after order status column, on order admin list (populate the column)
function action_manage_shop_order_posts_custom_column( $column, $post_id ) {    
    // Compare
    if ( $column == 'order_payment_url' ) {
        // Get order
        $order = wc_get_order( $post_id );
        
        // Get url
        $url = $order->get_checkout_payment_url();
        
        // Output
        echo '<a href="' . esc_url( $url ) . '">' . esc_html__( 'My url', 'woocommerce' ) . '</a>';
    }
}
add_action( 'manage_shop_order_posts_custom_column' , 'action_manage_shop_order_posts_custom_column', 10, 2 );

结果: