Skip to content

Instantly share code, notes, and snippets.

@Micemade
Created March 2, 2019 21:46
Show Gist options
  • Save Micemade/f56fbf55d0488ce3aeb264977108864d to your computer and use it in GitHub Desktop.
Save Micemade/f56fbf55d0488ce3aeb264977108864d to your computer and use it in GitHub Desktop.
Change priorities of WooCommerce template "content-product.php". Using global $wp_filter.
<?php
/**
* Change priority of hooked functions in "content-product.php"
*
* @return void
*/
function wc_content_product_priorities() {
global $wp_filter;
// Array of actions in
$content_product_actions = array(
'woocommerce_before_shop_loop_item',
'woocommerce_before_shop_loop_item_title',
'woocommerce_shop_loop_item_title',
'woocommerce_after_shop_loop_item_title',
'woocommerce_after_shop_loop_item',
);
foreach ( $content_product_actions as $action_tag ) {
$actions_array[] = isset( $wp_filter[ $action_tag ] ) ? $wp_filter[ $action_tag ]->callbacks : '';
if ( empty( $action_tag ) ) {
return;
}
// Actions with hooked functions grouped under priorities.
foreach ( $actions_array as $__action ) {
$all_actions[ $action_tag ] = $__action;
}
}
foreach ( $all_actions as $action => $func_names_array ) {
if ( empty( $func_names_array ) ) {
return;
}
foreach ( $func_names_array as $priority => $functions ) {
// Functions hooked under same action.
foreach ( $functions as $hooked_func => $args ) {
remove_action( $action, $hooked_func, $priority );
add_action( $action, $hooked_func, $priority + 10 );
}
}
}
}
add_action( 'init', 'wc_content_product_priorities', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment