Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show product name and purchase notes in My Accounts page in WooCommerce

In order to create a pay per view site for training video's via WooCommerce, I am using the "purchase note field" to send an email with a hyperlink to a video-page upon completion of the order. This works ok, but if you go to the my accounts page customers can't go to 'My Accounts' and see all their links in one place as they can with 'Available Downloads'.

I would like to show two extra fields in the table of the my-account.php page, "product (item) name" and "purchase note". Currently there are 4 fields: "order", "shipping", "total" and "status" in the standard table.

As I am not using shipping options (just a virtual product), I would like to change this field to product (item) name. As mentioned I would like to add the field "purchase notes" (this will show my video url upon completion of the payment) Important is that this purchase note field can only be displayed once the item is completed. It does this already in the order-details.php page, but I would like to have this in the table in my-accounts.php page

The current code for this purchase note field in the order-details.php field is:

// Show any purchase notes
            if ($order->status=='completed' || $order->status=='processing') :
                if ($purchase_note = get_post_meta( $_product->id, '_purchase_note', true)) :
                    echo '<tr class="product-purchase-note"><td colspan="3">' . apply_filters('the_content', $purchase_note) . '</td></tr>';
                endif;
            endif;

        endforeach;
    endif;

    do_action( 'woocommerce_order_items_table', $order );
    ?>

Can anyone show me what I need to change in my-account.php to accomplish these 2 extra fields in this page?

like image 793
user1731901 Avatar asked Oct 09 '12 13:10

user1731901


People also ask

How do you create a custom WooCommerce my account page?

Click on the Customizer and you will be redirected to the live editing panel of the plugin where you will see your WooCommerce My Account Page on the right and the customization tools on the left. The Navigation Option lets you customize the Account Page menu.


1 Answers

my-account.php is calling to several other templates, you need my-orders.php. Place a copy in your theme folder to make it update proof.

I am assuming you are using 1.6.6 here, because the my account page has changed from 2.0 and doesn't include the shipping address any longer.

remove line 50, which shows the shipping address. You can edit/replace this and call your purchase note with the following code:

get_post_meta( $order->id, '_purchase_note', true)

then you can get the product name (from your question I'm assuming you only have one product per order?):

foreach($order->get_items() as $item) {
    $product_name = $item['name'];
}

then simply call $product_name in an extra column (copy/paste/edit code another column)

like image 154
Ewout Avatar answered Nov 15 '22 08:11

Ewout