Advertisement
palsushobhan

wcfm-elementor-custom-store-tab

May 20th, 2025
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. add_action('wcfmmp_rewrite_rules_loaded', function ($wcfm_store_url) {
  2.     add_rewrite_rule($wcfm_store_url . '/([^/]+)/location?$', 'index.php?' . $wcfm_store_url . '=$matches[1]&location=true', 'top');
  3. }, 50);
  4. add_filter('query_vars', function ($vars) {
  5.     $vars[] = 'location';
  6.     return $vars;
  7. }, 50);
  8. function change_store_widget_content( $widget_content, $widget ) {
  9.     global $WCFMmp;
  10.     if(! wcfmmp_is_store_page()) return $widget_content;
  11.     $wcfm_store_url = wcfm_get_option( 'wcfm_store_url', 'store' );
  12.     $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
  13.     $store_id = 0;
  14.     if ( ! empty( $store_name ) ) {
  15.         $store_user = get_user_by( 'slug', $store_name );
  16.         $store_id = $store_user->ID;
  17.     }
  18.     if(!$store_id) return $widget_content;
  19.     if ( 'wcfmem-store-tabs' === $widget->get_name()) {
  20.         $location_tab_url = home_url( '/' . $wcfm_store_url . '/' . $store_name . '/location' );
  21.         $location_tab = '<li class="elementor-icon-list-item" >
  22.                            <a href="' . esc_url($location_tab_url) . '">
  23.                                <span class="elementor-icon-list-text">Location</span>
  24.                            </a>
  25.                        </li>';
  26.         $widget_content = str_replace('</ul>', $location_tab . '</ul>', $widget_content);
  27.     } elseif( 'wcfmem-store-tab-contents' === $widget->get_name() && get_query_var( $WCFMmp->wcfmmp_rewrite->store_endpoint('location'))) {
  28.         $widget_content = do_shortcode('[wcfm_store_info id="'.$store_id.'" data="store_name"]');
  29.     }
  30.     return $widget_content;
  31. }
  32. add_filter( 'elementor/widget/render_content', 'change_store_widget_content', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement