ujang giroud
ujang giroud

Reputation: 13

Add custom column with payment url on WooCommerce admin orders list

I want to add extra column on WooCommerce admin orders list with the payment url

The url is/look like this:

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

This thread is close for what i mean:

Modify woocommerce orders.php columns


This is my code attempt:

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;    
}

and this

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.
    }

}


    }

}

Unfortunately without the desired result. Any advice?

Upvotes: 1

Views: 420

Answers (1)

7uc1f3r
7uc1f3r

Reputation: 29624

Looks like you're mixing up frontend and backend. The url you refer to contains several answers.

  • Including code to add a column to "My account" orders table (frontend)
  • And code to add a column on WooCommerce admin orders list (backend)

Based on your code attempt you will want to add a column in the backend, and this can be done in the following way:

// 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 );

Result:

enter image description here

Upvotes: 1

Related Questions