Theming Exchange - Filtering Exchange Template Part Elements

(Difference between revisions)
Jump to: navigation, search
(Created page with "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 th...")
 
(One intermediate revision by one user not shown)
Line 21: Line 21:
 
This filter will return the $parts (which can be modified).
 
This filter will return the $parts (which can be modified).
  
===Examples===
+
===Example===
 
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:
 
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:
  
Line 36: Line 36:
 
add_action( 'it_exchange_get_content_cart_actions_elements', 'custom_exchange_filter_content_cart_actions' );
 
add_action( 'it_exchange_get_content_cart_actions_elements', 'custom_exchange_filter_content_cart_actions' );
 
</pre>
 
</pre>
 +
 +
'''Please note that these filters are for advanced users and should be used with caution.'''

Revision as of 07:17, September 24, 2013

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).

Example

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' );

Please note that these filters are for advanced users and should be used with caution.

Personal tools
Namespaces
Variants
Actions
iThemes Codex
Codex Navigation
Toolbox