Cartes

/**
* Adds a custom order action in the « Recent Orders » table of the WooCommerce account
* if a download ID is entered as a « custom_file » order custom field
* Button downloads custom files for the order
* Requires Download Monitor
*
* @param array $actions the actions available for the order
* @param \WC_Order $order the order object for this row
* @return array the updated order actions
*/
function sww_add_custom_file_order_action( $actions, $order ) {

// only add our button if the order is paid for\
if ( ! $order->is_paid() ) {
return $actions;
}

$order_id = is_callable( array( $order, ‘get_id’ ) ) ? $order->get_id() : $order->id;

// 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’, ‘sww_add_custom_file_order_action’, 10, 2 );
(If you don’t want the first check for paid orders, feel free to remove it!)