Template Hooks

This applies only to Business Directory 5.0 and later.

Overview

Introduction

Business Directory Plugin offers plugin and theme developers the ability to hook into some of our templates using WordPress actions.

Using these hooks extra HTML or output can be displayed on certain specific pages.

How to use the template hooks?

Since our template hooks are just regular WordPress actions, you need to familiarize yourself with the WordPress Plugin API and with the add_action() function in particular.

Once you’ve decided which hook to use (see list below) you have to edit your theme’s functions.php file or create a new plugin that takes advantage of said hook. See example below.

Example 1

The following PHP code would display “Thank you for your purchase!” after the checkout receipt is printed by BD.

<?php
function my_thankyou_function() {
    echo '<h4>Thank you for your purchase!</h4>';
}
add_action( 'wpbdp_after_render_receipt', 'my_thankyou_function' );
?>

Example 2

The following PHP code displays a message on top of every category page, with a special message (“Everybody likes pizza”) for just the category with slug “pizza”.

<?php

function pizza_places_message( $category ) {
    if ( 'pizza' == $category->slug ) {
        echo "<p>Everybody likes pizza.</p>";
    } else {
        echo "<p>This is category {$category->name}.</p>";
    }
}
add_action( 'wpbdp_before_category_page', 'pizza_places_message' );
?>

Template Actions

Hook Name Description Arguments
wpbdp_checkout_form_top Fired at the top of the checkout form. Used by the Discount Codes module to display its discount field. $payment - The payment object.
wpbdp_checkout_form_bottom Fired at the bottom of the checkout form. $payment - The payment object.
wpbdp_before_render_receipt Fired before rendering the receipt during the checkout process. $payment - The payment object.
wpbdp_after_render_receipt Fired after rendering the receipt during the checkout process. $payment - The payment object.
wpbdp_before_search_results Fired before rendering the search results. Only when there are results.  
wpbdp_after_search_results Fired after rendering the search results. Only when there are results.  
wpbdp_before_category_page Fired before rendering the category page. $category - The current category. A WP_Term object.
wpbdp_after_category_page Fired after rendering the category page. $category - The current category. A WP_Term object.
wpbdp_before_submit_listing_page Fired before rendering the submit listing page. $listing - An object with information about the current listing being submitted or edited.
wpbdp_after_submit_listing_page Fired after rendering the submit listing page. $listing - An object with information about the current listing being submitted or edited.