Advertisement
palsushobhan

change-store-tab-order

Mar 9th, 2022
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. add_filter( 'wcfmp_store_default_query_vars', function($tab, $vendor_id) {
  2.     global $WCFMmp, $wp;
  3.     if ( ! empty( $wp->query_vars['term_section'] ) || ! empty( $wp->query_vars['s'] ) || get_query_var( $WCFMmp->wcfmmp_rewrite->store_endpoint( 'products' ) ) ) {
  4.         return 'products';
  5.     } else {
  6.         return 'about';
  7.     }
  8. }, 20, 2 );
  9.  
  10. add_filter( 'wcfmmp_store_tabs', function ( $store_tabs, $id ) {
  11.     $new_store_tabs = array();
  12.     $keyOrder = [ 'about', 'policies', 'products', 'followers', 'reviews' ];
  13.     foreach ( $keyOrder as $key ) {
  14.         $new_store_tabs[$key] = $store_tabs[$key];
  15.     }
  16.     return array_filter( $new_store_tabs );
  17. }, 90, 2 );
  18.  
  19. add_filter( 'wcfmp_store_tabs_url', function ( $store_tab_url, $tab ) {
  20.     switch ( $tab ) {
  21.         case 'products':
  22.             $store_tab_url = $store_tab_url . 'products';
  23.             break;
  24.     }
  25.     return $store_tab_url;
  26. }, 10, 2 );
  27.  
  28. add_action( 'wcfmmp_rewrite_rules_loaded', function ( $wcfm_store_url ) {
  29.     global $WCFMmp;
  30.     add_rewrite_rule( $wcfm_store_url . '/([^/]+)/' . $WCFMmp->wcfmmp_rewrite->store_endpoint( 'products' ) . '?$', 'index.php?post_type=product&' . $wcfm_store_url . '=$matches[1]&' . $WCFMmp->wcfmmp_rewrite->store_endpoint( 'products' ) . '=true', 'top' );
  31.     add_rewrite_rule( $wcfm_store_url . '/([^/]+)/' . $WCFMmp->wcfmmp_rewrite->store_endpoint( 'products' ) . '/page/?([0-9]{1,})/?$', 'index.php?post_type=product&' . $wcfm_store_url . '=$matches[1]&paged=$matches[2]&' . $WCFMmp->wcfmmp_rewrite->store_endpoint( 'products' ) . '=true', 'top' );
  32. }, 8 );
  33.  
  34. add_action( 'init', function () {
  35.     add_rewrite_endpoint( 'products', EP_ROOT | EP_PAGES );
  36. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement