- This topic has 4 replies, 2 voices, and was last updated 7 years, 2 months ago by
Tom.
-
AuthorPosts
-
June 29, 2016 at 8:30 am #205371
GL
Hi Tom,
Ive been working on a child theme that makes extensive use of WooCommerce, I found that I cannot remove the hook for:
add_action(‘woocommerce_before_main_content’, ‘generate_woocommerce_start’, 10);
I know why I cant remove it, and I actually only need to remove it and rewrite it for one page (thus far), so using a woocommerce.php file is not an option either.
Anyhow… Can we possibly get a ! function_exists call added to the core around the generate wrapper functions?
Thank you
June 29, 2016 at 11:01 am #205416Tom
Lead DeveloperLead DeveloperHi there,
Why not do this?:
add_action( 'after_setup_theme','generate_remove_woocommerce_start' ); function generate_remove_woocommerce_start() { remove_action('woocommerce_before_main_content', 'generate_woocommerce_start', 10); }
Then you can add your own ๐
June 29, 2016 at 11:16 am #205425GL
Oh awesome! I forgot of the “after_setup_theme” function. Thanks
June 29, 2016 at 11:46 am #205434GL
Just tested, works, here’s my crazy function in case anyone wants to change just the single product page in the future:
add_action( 'after_setup_theme','generate_redo_woocommerce_wrappers' ); function generate_redo_woocommerce_wrappers() { remove_action('woocommerce_before_main_content', 'generate_woocommerce_start', 10 ); remove_action('woocommerce_after_main_content', 'generate_woocommerce_end', 10 ); add_action('woocommerce_before_main_content', 'generate_child_woocommerce_start', 10 ); add_action('woocommerce_after_main_content', 'generate_child_woocommerce_end', 10 ); } if ( ! function_exists( 'generate_child_woocommerce_start' ) ) : function generate_child_woocommerce_start() { if ( is_product() ) { return; } else { ?> <div id="primary" <?php generate_content_class();?>> <main id="main" <?php generate_main_class(); ?>> <?php do_action('generate_before_main_content'); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php generate_article_schema( 'CreativeWork' ); ?>> <div class="inside-article"> <?php do_action( 'generate_before_content'); ?> <div class="entry-content" itemprop="text"> <?php } } endif; if ( ! function_exists( 'generate_child_woocommerce_end' ) ) : function generate_child_woocommerce_end() { if ( is_product() ) { return; } else { ?> </div> <!-- .entry-content --> <?php do_action( 'generate_after_content'); ?> </div> <!-- .inside-article --> </article> <!-- #post-## --> <?php do_action('generate_after_main_content'); ?> </main> <!-- #main --> </div> <!-- #primary --> <?php } } endif;
I placed the actual wrappers I need to use in the content_single_product template file directly.
It’s kind of do and redo, and I don’t exactly like rewriting the same thing, but I couldn’t figure another way that would work. I tried a call for ( is_product() ) wrapped around various things but that wouldn’t do, so I couldn’t selectively apply ‘after_setup_theme’;
June 30, 2016 at 12:05 am #205564Tom
Lead DeveloperLead DeveloperAwesome, thanks for sharing your code! ๐
-
AuthorPosts
- You must be logged in to reply to this topic.