The latest update to CPTUI Extended, version 1.1, has added a slew of improvements, including new and enhanced shortcode templates for WooCommerce and Easy Digital Downloads. Since displaying your post types is the core feature of the plugin, we wanted to include a few templates that made it even easier. To learn how to create shortcodes and templates, keep reading!

Template Hooks

We’ve added a ton of template hooks to the core template files. There are hooks above and below most elements. These action hooks are there for you to add extra content. You can add things like post meta or any other information. Learn about the new template hooks in the Pluginize codex.

Easy Digital Downloads Hook Example

Let’s go over the code to add meta data to a template hook. The Easy Digital Downloads template displays the download title, featured image, description, pricing, and “Purchase” button. Digital products often have extra images of the product. You might be selling software and need to show off the features or want to show excerpt content from ebooks.

apppresser
Easy Digital Downloads shortcode before images

 

edd-images
Easy Digital Downloads shortcode with images

 

Example Hook for Adding Extra Product Images

Easy Digital Downloads offers many extensions, some for free. You will need to get the free EDD Download Images plugin. Install and activate this plugin and there will be a new meta box on download edit screens to add extra images. Don’t worry–these images do not display in your current theme without extra coding.

Let’s go over the code needed to add extra download images. We want to hook below the purchase button. The EDD Downloads Image plugin saves the image URLs as meta. So we get the post meta for edd_download_images and then echo it to display it.

function cptuiext_edd_axtra_images( $attributes ) {

    $images = array();
    $download_images = get_post_meta( get_the_ID(), 'edd_download_images', true );
    $images = $download_images;

    if ( $download_images ) {
        foreach ( $download_images as $download_image ) {
            $html = '<img class="edd-di-image" src="' . $download_image['image'] . '" />';
            echo apply_filters( 'cptui_ext_edd_di_display_images', $html, $download_image );
        }
    }

}
add_action( 'template_edd_after_checkout', 'cptuiext_edd_axtra_images' );

Make it Your Own!

You can add any post meta or other information that you want. The post global is accessible in the action hook and with the many hooks available in the template files, you can really customize the display to show what works best for you and your business!

Have a comment? Leave a reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.