admin管理员组文章数量:1317915
I've created a custom action in woocommerce in order to rewrite the breadcrumbs function and put it in another place into html, but it didn't work.
Firstly, I removed the original Woocommerce breadcrumb:
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
After, I added a custom action in my theme functions.php:
add_action('woo_breadcrumbs', 'woocommerce_breadcrumb', 20, 0);
And my custom function for breadcrumbs:
function woocommerce_breadcrumb( $args = array() ) {
$defaults = apply_filters( 'woocommerce_breadcrumb_defaults', array(
'delimiter' => ' / ',
'wrap_before' => '<nav class="woocommerce-breadcrumb" ' . ( is_single() ? 'itemprop="breadcrumb"' : '' ) . '>',
'wrap_after' => '</nav>',
'before' => '',
'after' => '',
'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ),
) );
$args = wp_parse_args( $args, $defaults );
wc_get_template( 'global/breadcrumb.php', $args );
}
Finally, I put this on my header.php:
<?php do_action('woo_breadcrumbs'); ?>
I have no idea what could be wrong here. Any help??
I've created a custom action in woocommerce in order to rewrite the breadcrumbs function and put it in another place into html, but it didn't work.
Firstly, I removed the original Woocommerce breadcrumb:
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
After, I added a custom action in my theme functions.php:
add_action('woo_breadcrumbs', 'woocommerce_breadcrumb', 20, 0);
And my custom function for breadcrumbs:
function woocommerce_breadcrumb( $args = array() ) {
$defaults = apply_filters( 'woocommerce_breadcrumb_defaults', array(
'delimiter' => ' / ',
'wrap_before' => '<nav class="woocommerce-breadcrumb" ' . ( is_single() ? 'itemprop="breadcrumb"' : '' ) . '>',
'wrap_after' => '</nav>',
'before' => '',
'after' => '',
'home' => _x( 'Home', 'breadcrumb', 'woocommerce' ),
) );
$args = wp_parse_args( $args, $defaults );
wc_get_template( 'global/breadcrumb.php', $args );
}
Finally, I put this on my header.php:
<?php do_action('woo_breadcrumbs'); ?>
I have no idea what could be wrong here. Any help??
Share Improve this question asked Oct 1, 2015 at 0:46 joaogdesignerjoaogdesigner 1036 bronze badges1 Answer
Reset to default 1It looks like your call to remove_action() has too many parameters.
https://codex.wordpress/Function_Reference/remove_action
Also, your call to add_action() is set to allow 0 parameters but your woocommerce_breadcrumb() definition expects one so you need to fix that mismatch.
https://codex.wordpress/Function_Reference/add_action
I haven't run the code locally but those are the only issues I'm seeing. I hope that helps solve the problem.
SIDE NOTE: For my own peace of mind I like to give my functions unique names, rather than reusing the name of a function I'm overriding. Not all software developers wrap their definitions in function_exists() checks so I try to err on the side of caution there. WooCommerce does use functions_exists() checks so you're safe with that approach here.
本文标签: Custom action not working in Woocommerce
版权声明:本文标题:Custom action not working in Woocommerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742023088a2415042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论