-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathadds-a-custom-order-action-in-the-recent-orders-table-of-the-woocommerce-account.code-snippets.xml
37 lines (37 loc) · 1.98 KB
/
adds-a-custom-order-action-in-the-recent-orders-table-of-the-woocommerce-account.code-snippets.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a code snippets export file generated by the Code Snippets WordPress plugin. -->
<!-- https://wordpress.org/plugins/code-snippets -->
<!-- To import these snippets a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Install the Code Snippets plugin using the directions provided at the above link. -->
<!-- 3. Go to 'Tools: Import' in the WordPress admin panel. -->
<!-- 4. Click on the "Code Snippets" importer in the list -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. Code Snippets will then import all of the snippets and associated information contained in this file into your site. -->
<!-- 7. You will then have to visit the 'Snippets: All Snippets' admin menu and activate desired snippets. -->
<!-- generator="Code Snippets/2.9.4" created="2017-09-29 16:51" -->
<snippets>
<snippet scope="2">
<name>Adds a custom order action in the "Recent Orders" table of the WooCommerce account</name>
<desc></desc>
<tags>custom, order, file, download, woocommerce, my, account</tags>
<code>function wc_add_custom_file_order_action( $actions, $order ) {
// only add our button if the order is paid for
// if using WC 2.5+, can simplify this to: if ( ! $order->is_paid() )
if ( ! ( $order->has_status( 'processing' ) || $order->has_status( 'completed' ) ) ) {
return $actions;
}
// add our action if the order has the custom_file field set
if ( $file_id = (int) get_post_meta( $order->id, 'custom_file', true ) ) {
$actions['files'] = array(
'url' => trailingslashit( get_site_url() ) . trailingslashit( get_option( 'dlm_download_endpoint' ) ) . $file_id,
'name' => __( 'Get Files', 'my-textdomain' ),
);
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'wc_add_custom_file_order_action', 10, 2 );</code>
</snippet>
</snippets>