• Hi,
    1. Is there a new easier way to create custom tabs on the vendor store page ?

    I was given this code long ago but my theme Rehub has had some major updates and it has stopped working.

    2. As before according to your instructions, I created two folders wcfm/store in my child theme followed by the code : store/wcfmmp-view-store-art-works.php

    3. I placed my shortcode

    <?
        php echo do_shortcode( ‘[RH_ELEMENTOR id=”10332″]’ ); 
    ?> 

    To: store/wcfmmp-view-store-art-works.php but it crashes my wesbite.

    Any help would be much appreciated !

    //Wcfm-Custom-Tabs//

    <?
    add_action( ‘wcfmmp_rewrite_rules_loaded’, function( $wcfm_store_url ) {
    add_rewrite_rule( $wcfm_store_url.’/([^/]+)/art_works?$’, ‘index.php?’.$wcfm_store_url.’=$matches[1]&art_works=true’, ‘top’ );
    add_rewrite_rule( $wcfm_store_url.’/([^/]+)/art_works/page/?([0-9]{1,})/?$’, ‘index.php?’.$wcfm_store_url.’=$matches[1]&paged=$matches[2]&art_works=true’, ‘top’ );
    }, 50 );
    
    add_filter( ‘query_vars’, function( $vars ) {
    $vars[] = ‘art_works’;
    return $vars;
    }, 50 );
    
    add_filter( ‘wcfmmp_store_tabs’, function( $store_tabs, $store_id ) {
    $store_tabs[‘art_works’] = ‘Art Works’;
    return $store_tabs;
    }, 50, 2 );
    
    add_filter( ‘wcfmp_store_tabs_url’, function( $store_tab_url, $tab ) {
    if( $tab == ‘art_works’ ) {
    $store_tab_url .= ‘art_works’;
    }
    return $store_tab_url;
    }, 50, 2 );
    
    add_filter( ‘wcfmp_store_default_query_vars’, function( $query_var ) {
    global $WCFM, $WCFMmp;
    
    if ( get_query_var( ‘art_works’ ) ) {
    $query_var = ‘art_works’;
    }
    return $query_var;
    }, 50 );
    
    add_filter( ‘wcfmp_store_default_template’, function( $template, $tab ) {
    if( $tab == ‘art_works’ ) {
    $template = ‘store/wcfmmp-view-store-art-works.php’;
    }
    return $template;
    }, 50, 2);
    
    ?>
    • This topic was modified 4 years, 3 months ago by marzmuso.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Please check at wp-admin -> WooCommerce -> Status -> Logs -> fatal_erros log -> is any error generated?

    php echo do_shortcode( ‘[RH_ELEMENTOR id=”10332″]’ );

    – Between, this single and double quotes are not valid ones. Not sure, are these changed during copy-paste or you are using like!

    Thread Starter marzmuso

    (@marzmuso)

    Hi,
    I’m not getting errors or fatal logs. Those quotes do look like they were corrupted from copy. It actually looks like this below.

    <?
        php echo do_shortcode( [RH_ELEMENTOR id=”10332″] ); 
    ?> 

    This code is whats crashing the site:

    add_action( ‘wcfmmp_rewrite_rules_loaded’, function( $wcfm_store_url ) {
    add_rewrite_rule( $wcfm_store_url.’/([^/]+)/art_works?$’, ‘index.php?’.$wcfm_store_url.’=$matches[1]&art_works=true’, ‘top’ );
    add_rewrite_rule( $wcfm_store_url.’/([^/]+)/art_works/page/?([0-9]{1,})/?$’, ‘index.php?’.$wcfm_store_url.’=$matches[1]&paged=$matches[2]&art_works=true’, ‘top’ );
    }, 50 );
    
    add_filter( ‘query_vars’, function( $vars ) {
    $vars[] = ‘art_works’;
    return $vars;
    }, 50 );
    
    add_filter( ‘wcfmmp_store_tabs’, function( $store_tabs, $store_id ) {
    $store_tabs[‘art_works’] = ‘Art Works’;
    return $store_tabs;
    }, 50, 2 );
    
    add_filter( ‘wcfmp_store_tabs_url’, function( $store_tab_url, $tab ) {
    if( $tab == ‘art_works’ ) {
    $store_tab_url .= ‘art_works’;
    }
    return $store_tab_url;
    }, 50, 2 );
    
    add_filter( ‘wcfmp_store_default_query_vars’, function( $query_var ) {
    global $WCFM, $WCFMmp;
    
    if ( get_query_var( ‘art_works’ ) ) {
    $query_var = ‘art_works’;
    }
    return $query_var;
    }, 50 );
    
    add_filter( ‘wcfmp_store_default_template’, function( $template, $tab ) {
    if( $tab == ‘art_works’ ) {
    $template = ‘store/wcfmmp-view-store-art-works.php’;
    }
    return $template;
    }, 50, 2);

    Please send me revised copy of this code to put in function.php file ?
    Thanks

    Plugin Author WC Lovers

    (@wclovers)

    Here is that code –

    add_action( 'wcfmmp_rewrite_rules_loaded', function( $wcfm_store_url ) {
    	add_rewrite_rule( $wcfm_store_url.'/([^/]+)/art_works?$', 'index.php?'.$wcfm_store_url.'=$matches[1]&art_works=true', 'top' );
    	add_rewrite_rule( $wcfm_store_url.'/([^/]+)/art_works/page/?([0-9]{1,})/?$', 'index.php?'.$wcfm_store_url.'=$matches[1]&paged=$matches[2]&art_works=true', 'top' );
    }, 50 );
    
    add_filter( 'query_vars', function( $vars ) {
    	$vars[] = 'art_works';
    	return $vars;
    }, 50 );
    
    add_filter( 'wcfmmp_store_tabs', function( $store_tabs, $store_id ) {
      $store_tabs['art_works'] = 'Art Works';
      return $store_tabs;
    }, 50, 2 );
    
    add_filter( 'wcfmp_store_tabs_url', function( $store_tab_url, $tab ) {
    	if( $tab == 'art_works' ) {
    		$store_tab_url .= 'art_works';
    	}
    	return $store_tab_url;
    }, 50, 2 );
    
    add_filter( 'wcfmp_store_default_query_vars', function( $query_var ) {
    	global $WCFM, $WCFMmp;
    	
    	if ( get_query_var( 'art_works' ) ) {
    		$query_var = 'art_works';
    	}
    	return $query_var;
    }, 50 );
    
    add_filter( 'wcfmmp_store_default_template', function( $template, $tab ) {
      if( $tab == 'art_works' ) {
      	$template = 'store/wcfmmp-view-store-art-works.php';
      }
      return $template;
    }, 50, 2);
    Thread Starter marzmuso

    (@marzmuso)

    Did you correct something or is it exactly the same code as mine above ?

    Plugin Author WC Lovers

    (@wclovers)

    This is valid code and working fine at my environment.

    Thread Starter marzmuso

    (@marzmuso)

    So this is correct ? Quotes are valid in elementor and display all over the site except your code.

    Please send your shortcode example ?

    <? php 
    echo do_shortcode( [RH_ELEMENTOR id=”10332″] ); 
    ?> 
    Plugin Author WC Lovers

    (@wclovers)

    Where have you added this code, show me a screenshot please.

    Thread Starter marzmuso

    (@marzmuso)

    Hi,

    I have found this code on wc lovers website which is different from this older code.

    It successfully shows the NEW tab, but it does not render any content /shortcode or text, it only the products ?

    Please can you help ?

    ///Custom Tab-Vendor///
    
    add_filter( 'wcfmmp_store_tabs', 'custom_wcfmmp_store_tabs',90,2);
    function custom_wcfmmp_store_tabs($store_tabs, $vendor_id) {
        
        $store_tabs['newtab'] =  __( 'NEW Tab', 'wc-multivendor-marketplace' );
        return $store_tabs;
    }
    add_filter( 'wcfmp_store_default_query_vars', 'wcfm_store_events_default_query_var' );
    function wcfm_store_events_default_query_var( $query_var ) {
      global $WCFM, $WCFMmp;
      
      if ( get_query_var( 'newtab' ) ) {
        $query_var = 'newtab';
      }
      return $query_var;
    }
    add_filter( 'wcfmp_store_tabs_url', 'new_wcfmp_store_tabs_url',10,2);
    function new_wcfmp_store_tabs_url($store_tab_url, $tab) {
      switch( $tab ) {      
         
          case 'newtab':        
            $store_tab_url = $store_tab_url.'newtab';
          break; 
        }
      return $store_tab_url;
    }
    add_action( 'wcfmmp_rewrite_rules_loaded', 'new_register_rule', 8 );
    function new_register_rule($wcfm_store_url) {
      global $WCFM, $WCFMmp;
      add_rewrite_rule( $wcfm_store_url.'/([^/]+)/'.$WCFMmp->wcfmmp_rewrite->store_endpoint('newtab').'?$', 'index.php?post_type=product&'.$wcfm_store_url.'=$matches[1]&'.$WCFMmp->wcfmmp_rewrite->store_endpoint('newtab').'=true', 'top' );
      add_rewrite_rule( $wcfm_store_url.'/([^/]+)/'.$WCFMmp->wcfmmp_rewrite->store_endpoint('newtab').'/page/?([0-9]{1,})/?$', 'index.php?post_type=product&'.$wcfm_store_url.'=$matches[1]&paged=$matches[2]&'.$WCFMmp->wcfmmp_rewrite->store_endpoint('newtab').'=true', 'top' );
    }
    function wcfm_vendor_profile_custom_endpoint() {
      global $WCFM, $WCFMmp,$WCFMu;
      $wcfm_store_url = get_option( 'wcfm_store_url', 'store' ); 
      add_rewrite_endpoint( 'newtab', EP_ROOT | EP_PAGES );
    } 
    add_action( 'init', 'wcfm_vendor_profile_custom_endpoint',12 );
    

    Directory for shortcode is in my child theme rehub-blankchild:

    store/wcfmmp-view-store-newtab.php

    • This reply was modified 3 years, 10 months ago by marzmuso.
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Store “Custom Tab” PHP code crashes my site’ is closed to new replies.