Theming Exchange - Filtering Exchange Template Part Elements

From IThemes Codex
Revision as of 11:03, September 23, 2013 by Kopepasah (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In Most of the tempalte parts for exchange you will notice a function: it_exchange_get_template_part_elements().

This function gives both theme and addons developers the power to alter what element(s) each template part loops through by providing a filter based on the context and detail that the function calls for.

Function Call

	it_exchange_get_template_part_elements( $context, $detail, $parts )

Filter Tag

	'it_exchange_get_context_detail_elements'

For example, in lib/templates/content-cart/loops/actions.php the function calls for the context 'content_cart' and the detail 'actions'. Our filter tag for modifying this is as follows.

	'it_exchange_content_cart_actions_elements'

This filter will return the $parts (which can be modified).

Examples

For the filter above (it_exchange_get_content_cart_actions_elements), let's say we want to remove the apply-coupon action. We can do this by filtering the elements of that array like so:

function custom_exchange_filter_content_cart_actions( $parts ) {
	foreach ( $parts as $key => $part ) {
		if ( 'apply-coupon' == $part ) {
			unset( $parts[$key] );
		}
	}
	
	return $parts;
}
add_action( 'it_exchange_get_content_cart_actions_elements', 'custom_exchange_filter_content_cart_actions' );
Personal tools
Namespaces
Variants
Actions
iThemes Codex
Codex Navigation
Toolbox