! exist woocommerce wrappers

Home Forums Support ! exist woocommerce wrappers

Home Forums Support ! exist woocommerce wrappers

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #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

    #205416
    Tom
    Lead Developer
    Lead Developer

    Hi 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 ๐Ÿ™‚

    #205425
    GL

    Oh awesome! I forgot of the “after_setup_theme” function. Thanks

    #205434
    GL

    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’;

    #205564
    Tom
    Lead Developer
    Lead Developer

    Awesome, thanks for sharing your code! ๐Ÿ™‚

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.