Robin Cornett – Easy Digital Downloads Development https://easydigitaldownloads.com/development Official development blog for Easy Digital Downloads Wed, 15 Dec 2021 21:32:52 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 https://easydigitaldownloads.com/development/files/2015/11/icon-256x256-150x150.png Robin Cornett – Easy Digital Downloads Development https://easydigitaldownloads.com/development 32 32 Invoices 1.2 https://easydigitaldownloads.com/development/2021/04/12/invoices-1-2/ https://easydigitaldownloads.com/development/2021/04/12/invoices-1-2/#comments Mon, 12 Apr 2021 12:20:20 +0000 https://easydigitaldownloads.com/development/?p=1050

Continue reading →

]]>
Easy Digital Downloads – Invoices 1.2 is a huge release, providing significant extensibility while maintaining backwards compatibility.

The CSS has been simplified and updated. The new invoices will look slightly different, as the overall appearance and font stack has been modernized, but out of the box, the new invoices should be very similar to the old.

Where version 1.2 really shines is that now, store owners can modify the invoice template. The following template files are now available:

  • invoice.php: This is the primary template, and consists only of the basic HTML markup, and some new custom hooks.
  • invoice-contacts.php: This template outputs the storefront and customer information.
  • invoice-table.php: This template outputs the primary “receipt” of the invoice.
  • invoice-additional-info.php: This template includes any custom notes added by the customer, as well as custom notes from the storefront (this is a new setting in 1.2).

As with any EDD templates, these can be overridden by copying them to a directory called edd_templates in the active theme folder.

In addition to the templates, EDD Invoices now includes multiple hooks in the invoice so that a store owner can add additional information wherever it’s needed:

  • edd_invoices_invoice_head: This hook fires in the head of the HTML output for the invoice. One new feature is that the invoice stylesheet is now output using this hook. The same hook can be used to load an additional custom stylesheet.
  • edd_invoices_invoice_header: This hook is used to output the invoice logo (if set), the invoice number, and (new in 1.2) the order status and purchase date.
  • edd_invoices_invoice_contacts: The invoice-contacts.php template is loaded in this hook.
  • edd_invoices_invoice_items_table: The invoice-table.php template is loaded in this hook.
  • edd_invoices_invoice_additional_info: The invoice-additional-info.php template is loaded in this hook.
  • edd_invoices_invoice_footer: EDD Invoices adds action buttons (print, back) using this hook. These are not included in the printed version of the invoice.

Each hook uses either the order object (in EDD 3.0) or the payment object (EDD 2.x).

Some invoice content is output directly in the templates, but some of it requires a bit more logic, so 1.2 also introduces some helper functions:

  • edd_invoices_get_order_items: This function gets the necessary information for each item in the order: the item ID, the price, the product name, and the price ID. The data is returned to the template as an array.
  • edd_invoices_get_order_discounts: This function gets the discounts applied to the order. In EDD 2.9/2.10, the discount code is displayed on the invoice. Because much more specific information is available in 3.0, those invoices will include the amount of each discount, and (for percentage discounts) the discount rate.
  • edd_invoices_get_custom_order_meta: This function gets the customer’s notes and/or VAT for the order. It works for the metadata in both EDD 2.x and 3.0.
  • edd_invoices_get_order_date: This function gets the order date, which is a different property in EDD 3.0, and requires a little more fallback work for renewal payments in 2.x.

Functions which output directly to the invoice are in the includes/template-functions.php file.

EDD Invoices 1.2 is ready for Easy Digital Downloads 3.0

Just as orders are stored in a custom database table in EDD 3.0, order meta will be as well. Invoices saves custom meta–the option VAT for the customer and any notes the customer adds to the invoice. Invoices 1.2 will migrate this custom meta to the new order meta table when you upgrade to EDD 3.0.

Additionally, the new templates and hooks use the order object in EDD 3.0. This is both more detailed and simpler than the comparable payment object, and allows store owners to access much more specific information about each order and order item.

]]>
https://easydigitaldownloads.com/development/2021/04/12/invoices-1-2/feed/ 1
How to Add Custom Sections to Order Details in EDD 3.0 https://easydigitaldownloads.com/development/2021/03/22/custom-order-sections/ https://easydigitaldownloads.com/development/2021/03/22/custom-order-sections/#respond Mon, 22 Mar 2021 13:58:00 +0000 https://easydigitaldownloads.com/development/?p=1025

Continue reading →

]]>
There is a lot of information stored about every order placed in an Easy Digital Downloads storefront. In 3.0, the Order Details screen has been completely updated to be easier to read and manage.

One big change is the addition of order sections, which allow necessary, but less immediate, data to be hidden on the initial screen load. Core sections included in Easy Digital Downloads are:

  • Customer (default)
  • Email
  • Address
  • Notes
  • Logs

Extension authors may want to add their own data to these sections as well. To do so, start with registering the custom section:

add_filter( 'edd_get_order_details_sections', 'prefix_add_custom_order_section', 10, 2 );
/**
 * Adds the custom details as an order section in EDD 3.0.
 *
 * @since 2.3.9
 * @param array  $sections The array of order sections.
 * @param object $order    The order object.
 * @return array
 */
function prefix_add_custom_order_section( $sections, $order ) {

    $sections[] = array(
        'id'       => 'prefix_order_section',
        'label'    => __( 'Custom Section' ),
        'icon'     => 'admin-multisite',
        'callback' => 'prefix_show_custom_order_section',
    );

    return $sections;
}

This will add your new custom section to the end of the array of sections (after Logs). Each section has four parameters:

  • id: The unique ID of the section
  • label: The label which will show in the navigation menu
  • icon: The dashicon to use with the navigation label
  • callback: the function which will output the section content

The next step is to build your prefix_show_custom_order_section function. This accepts one parameter, the order object. It would begin with something like this:

/** * Shows the custom order section in EDD 3.0.
 *
 * @param \EDD\Orders\Order object $order The order object.
 * @return void
 */
function prefix_show_custom_order_section( $order ) {
    printf( '<h3 class="hndle">%s</h3>', esc_html__( 'Custom Section Heading' ) );
    // Custom code for the section
}

Custom order data can be varied. EDD Simple Shipping, for example, registers two custom sections: one for the shipping address and one for tracking information. These are displayed as individual metabox style boxes in EDD 2.10, but as order sections in 3.0.

Screenshot of the Shipping order section.
Simple Shipping registers two custom order sections: Shipping and Tracking.

Note that in EDD 2.10, the parameter that’s available to a metabox is just the $payment_id, and in EDD 3.0, the entire order object is available. To be compatible with both versions of EDD, you may want to call a separate function from your prefix_show_custom_order_section function, and just pass the $order->id to it. It’s a little extra work to update the code to work with both the order sections and the edd_view_order_details_billing_after hook, which is what metaboxes in 2.10 would use, but it’s worth doing to seamlessly integrate into the new EDD.

]]>
https://easydigitaldownloads.com/development/2021/03/22/custom-order-sections/feed/ 0