Below, you’ll find a detailed guide on how to add the WooCommerce Menu Extension Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WooCommerce Menu Extension Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the WooCommerce Menu Extension Plugin and the shortcodes it provides:
"WooCommerce Menu Extension is a powerful plugin that enhances your WordPress eCommerce site by adding effective and customizable navigation options. It improves user experience and boosts sales."
- [aishop]
- [aicart]
- [aibasket]
- [ailogin]
- [ailogout]
- [ailoginout]
- [aicheckout]
- [aiterms]
- [aimyaccount]
- [aisearch]
- [aiproductcat]
WooCommerce Menu Extension [aishop] Shortcode
The ‘aishop’ shortcode from the WooCommerce Menu Extension plugin is designed to generate a link to your WooCommerce shop page. This shortcode accepts an optional ‘edit_tag’ parameter, allowing you to customize the outputted HTML tag. By default, the link text will be ‘Shop’, but you can override this by providing content within the shortcode.
Shortcode: [aishop]
Parameters
Here is a list of all possible aishop shortcode parameters and attributes:
edit_tag
– Additional HTML attributes for the link elementcontent
– The anchor text for the shop link
Examples and Usage
Basic example – A simple usage of the ‘aishop’ shortcode to create a link to the shop page.
[aishop /]
Advanced examples
Adding custom text to the ‘aishop’ shortcode, which will be displayed as the link text instead of the default ‘Shop’.
[aishop]Visit Our Shop Now![/aishop]
Adding an ‘edit_tag’ attribute to the ‘aishop’ shortcode, allowing for the addition of custom HTML tags within the link. In this example, we are adding a class to style the link.
[aishop edit_tag=" class='custom-class'"]Check Out Our Products[/aishop]
PHP Function Code
In case you have difficulties debugging what causing issues with [aishop]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'aishop', 'aiwoo_shortcode_shop' );
Shortcode PHP function:
function aiwoo_shortcode_shop( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => ""
), $atts ) );
$edit_tag = esc_html( strip_tags( $edit_tag ) );
$href = get_permalink( wc_get_page_id( 'shop' ) );
$content = $content != '' ? $content : __( 'Shop' );
return '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [aicart] Shortcode
The ‘aicart’ shortcode from the Woocommerce Menu Extension plugin is used to generate a link to the cart page. It allows customization of the link text and optional HTML tags for styling.
Shortcode: [aicart]
Parameters
Here is a list of all possible aicart shortcode parameters and attributes:
edit_tag
– Allows you to add HTML tags to customize the linkcontent
– Changes the default ‘Cart’ text of the link
Examples and Usage
Basic example – The shortcode ‘aicart’ is used to display a link to the WooCommerce cart page. The link text can be customized through the content parameter.
[aicart]View Cart[/aicart]
Advanced examples
1. Using the shortcode to display a link to the cart page with a custom HTML tag. The ‘edit_tag’ parameter allows you to add any HTML tag to the link. For instance, you can add a class to style the link with CSS.
[aicart edit_tag="class='my-custom-class'"]View Cart[/aicart]
2. The shortcode can also be used without any content. In this case, it will display a link to the cart page with the default text ‘Cart’.
[aicart /]
3. You can also combine both parameters to display a link with custom text and HTML tag.
[aicart edit_tag="class='my-custom-class'"]Checkout Now[/aicart]
PHP Function Code
In case you have difficulties debugging what causing issues with [aicart]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'aicart', 'aiwoo_shortcode_cart' );
Shortcode PHP function:
function aiwoo_shortcode_cart( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => ""
), $atts ) );
$edit_tag = esc_html( strip_tags( $edit_tag ) );
$href = get_permalink( wc_get_page_id( 'cart' ) );
$content = $content != '' ? $content : __( 'Cart' );
return '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [aibasket] Shortcode
The ‘aibasket’ shortcode from the WooCommerce Menu Extension plugin displays the total number of items and total cost in the user’s shopping cart. It also provides a link to the cart page.
Shortcode: [aibasket]
Parameters
Here is a list of all possible aibasket shortcode parameters and attributes:
edit_tag
– Defines additional HTML attributes for the basket link
Examples and Usage
Basic example – A simple usage of the ‘aibasket’ shortcode without any additional parameters. It will display the number of items in the cart and the total cost.
[aibasket /]
Advanced examples
Adding a ‘edit_tag’ parameter to the ‘aibasket’ shortcode. This allows you to add extra HTML tags to the link that is generated. For example, you could add a class to style the link with CSS.
[aibasket edit_tag=" class='button button-primary'"/]
Combining the ‘aibasket’ shortcode with other shortcodes. In this example, the ‘aibasket’ shortcode is wrapped around a ‘product’ shortcode. This will display a link to the cart, with the number of items and total cost, but the link text will be the name of the product with the given ID.
[aibasket][product id="99"][/aibasket]
PHP Function Code
In case you have difficulties debugging what causing issues with [aibasket]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'aibasket', 'aiwoo_shortcode_basket' );
Shortcode PHP function:
function aiwoo_shortcode_basket( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => ""
), $atts ) );
$edit_tag = esc_html( strip_tags( $edit_tag ) );
$href = get_permalink( wc_get_page_id( 'cart' ) );
$content = sprintf (_n( '%d item', '%d items', WC()->cart->cart_contents_count ), WC()->cart->cart_contents_count ) .' - '. WC()->cart->get_cart_total();
return '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [ailogin] Shortcode
The ‘ailogin’ shortcode from the Woocommerce Menu Extension plugin creates a login link. It directs users to the ‘myaccount’ page when clicked. This shortcode allows customization through the “edit_tag” attribute, enabling changes to the HTML tag surrounding the link. The default text for the link is ‘Log In’, but it can be altered by adding content within the shortcode.
Shortcode: [ailogin]
Parameters
Here is a list of all possible ailogin shortcode parameters and attributes:
edit_tag
– Additional HTML attributes for the login link.
Examples and Usage
Basic example – A simple usage of the ‘ailogin’ shortcode to display a login link. The link text will default to ‘Log In’.
[ailogin /]
Advanced example – An extended usage of the ‘ailogin’ shortcode. Here, the ‘edit_tag’ attribute is being used to add custom HTML tags to the link. The content within the shortcode is used to customize the link text.
[ailogin edit_tag='class="custom-class"']Click Here to Login[/ailogin]
Advanced example – Another advanced usage of the ‘ailogin’ shortcode. In this example, the ‘edit_tag’ attribute is being used to add multiple HTML attributes to the link, including a custom class and a target attribute. The content within the shortcode is again used to customize the link text.
[ailogin edit_tag='class="custom-class" target="_blank"']Sign In[/ailogin]
Remember, the ‘edit_tag’ attribute is intended for adding HTML attributes to the login link. It should contain valid HTML attribute syntax, and any text content should be placed between the opening and closing shortcode tags.
PHP Function Code
In case you have difficulties debugging what causing issues with [ailogin]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'ailogin', 'aiwoo_shortcode_login' );
Shortcode PHP function:
function aiwoo_shortcode_login( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => ""
), $atts ) );
$edit_tag = esc_html( strip_tags( $edit_tag ) );
$href = get_permalink( wc_get_page_id( 'myaccount' ) );
$content = $content != '' ? $content : __( 'Log In' );
return '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [ailogout] Shortcode
The ‘ailogout’ shortcode from the Woocommerce Menu Extension plugin enables a user-friendly logout function. It redirects users to the ‘myaccount’ page post-logout. The shortcode displays a personalized greeting with the user’s login name, followed by a logout link. If no specific content is provided, it defaults to ‘Logout’.
Shortcode: [ailogout]
Parameters
Here is a list of all possible ailogout shortcode parameters and attributes:
edit_tag
– Adjusts the HTML tags of the logout linkredirect
– Determines the page users are redirected to after logging out
Examples and Usage
Basic example – The following shortcode allows a user to log out, redirecting them to the ‘My Account’ page by default.
[ailogout /]
Advanced examples
The following shortcode allows a user to log out and redirects them to a custom page. The ‘redirect’ attribute is used to specify the URL of the page to which the user will be redirected after logging out.
[ailogout redirect="https://www.yourwebsite.com/custom-page" /]
In this example, the ‘edit_tag’ attribute is used to add additional HTML tags to the logout link. The shortcode will return a logout link with the specified HTML tags. The tags are stripped of any harmful code before being added to the link.
[ailogout edit_tag="" /]
Combining both ‘redirect’ and ‘edit_tag’ attributes, you can create a custom logout link that redirects to a specified page and includes additional HTML tags.
[ailogout redirect="https://www.yourwebsite.com/custom-page" edit_tag="" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ailogout]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'ailogout', 'aiwoo_shortcode_logout' );
Shortcode PHP function:
function aiwoo_shortcode_logout( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => "",
"redirect" => get_permalink( wc_get_page_id( 'myaccount' ) )
), $atts ) );
$href = wp_logout_url( $redirect );
$edit_tag = esc_html( strip_tags( $edit_tag ) );
$content = $content != '' ? $content : __( 'Logout' );
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
return 'Hello ' . $current_user->user_login . ', <a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [ailoginout] Shortcode
The ‘ailoginout’ shortcode from the Woocommerce Menu Extension plugin provides a simplified login/logout functionality. It redirects users to the ‘myaccount’ page post-login or logout. This shortcode checks user login status and displays ‘Logout’ for logged-in users and ‘Log In’ for guests. It also allows customization of the display message.
Shortcode: [ailoginout]
Parameters
Here is a list of all possible ailoginout shortcode parameters and attributes:
edit_tag
– Allows adding HTML tags to the link textredirect
– Defines the page to go after login/logout
Examples and Usage
Basic example – A simple usage of the shortcode to direct users to the ‘myaccount’ page upon login or logout.
[ailoginout /]
Advanced examples
Using the shortcode to redirect users to a specific page upon login or logout by setting the ‘redirect’ attribute to the desired permalink.
[ailoginout redirect="https://yourwebsite.com/yourpage" /]
Using the shortcode to customize the text displayed to logged in and logged out users. The ‘|’ character is used to split the messages for logged in and logged out users.
[ailoginout]Welcome back|Please log in[/ailoginout]
Combining both the ‘redirect’ attribute and custom messages for a more tailored user experience.
[ailoginout redirect="https://yourwebsite.com/yourpage"]Welcome back|Please log in[/ailoginout]
Adding an ‘edit_tag’ attribute to the shortcode for additional customization. The ‘edit_tag’ attribute allows you to add additional HTML tags to the login/logout link.
[ailoginout edit_tag="class='my-class'" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ailoginout]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'ailoginout', 'aiwoo_shortcode_loginout' );
Shortcode PHP function:
function aiwoo_shortcode_loginout( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => "",
"redirect" => get_permalink( wc_get_page_id( 'myaccount' ) )
), $atts ) );
$edit_tag = strip_tags( $edit_tag );
$href = is_user_logged_in() ? wp_logout_url( $redirect ) : get_permalink( wc_get_page_id( 'myaccount' ) );
if( $content && strstr( $content, '|' ) != '' ) { // the "|" char is used to split titles
$content = explode( '|', $content );
$content = is_user_logged_in() ? $content[1] : $content[0];
}else{
$current_user = wp_get_current_user();
$message = is_user_logged_in() ? __( 'Hello ' ) . $current_user->user_login . ', ' : '';
$content = is_user_logged_in() ? __( 'Logout' ) : __( 'Log In' );
}
return $message . '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [aicheckout] Shortcode
The Woocommerce Menu Extension shortcode ‘aicheckout’ creates a clickable link to the checkout page. It allows customization of the link text and HTML tags for styling.
Shortcode: [aicheckout]
Parameters
Here is a list of all possible aicheckout shortcode parameters and attributes:
edit_tag
– Specifies additional HTML attributes for the checkout linkcontent
– Defines custom text for the checkout link
Examples and Usage
Basic example – The shortcode ‘aicheckout’ is utilized to create a checkout link. The content within the link can be customized.
[aicheckout]Proceed to Checkout[/aicheckout]
Advanced examples
In this example, the ‘edit_tag’ attribute is used to add additional HTML attributes to the checkout link. In this case, a class ‘myClass’ is added to the link.
[aicheckout edit_tag='class="myClass"']Proceed to Checkout[/aicheckout]
Another advanced use of the shortcode is to change the text of the link based on the context. This can be useful for multilingual sites or sites that want to provide different instructions based on the user’s actions.
[aicheckout]Complete Your Purchase[/aicheckout]
Finally, the shortcode can be used without any content to display the default ‘Checkout’ text. This is useful for sites that want to maintain a consistent checkout link across all pages.
[aicheckout][/aicheckout]
PHP Function Code
In case you have difficulties debugging what causing issues with [aicheckout]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'aicheckout', 'aiwoo_shortcode_checkout' );
Shortcode PHP function:
function aiwoo_shortcode_checkout( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => ""
), $atts ) );
$edit_tag = esc_html( strip_tags( $edit_tag ) );
$href = get_permalink( wc_get_page_id( 'checkout' ) );
$content = $content != '' ? $content : __( 'Checkout' );
return '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [aiterms] Shortcode
The Aiterms shortcode is designed to create a link to the WooCommerce ‘Terms’ page. It allows customization of the link text and additional HTML tags. The ‘edit_tag’ attribute lets you add extra HTML attributes to the link. By default, it links to the ‘Terms’ page but the link text can be customized with the shortcode content.
Shortcode: [aiterms]
Parameters
Here is a list of all possible aiterms shortcode parameters and attributes:
edit_tag
– Allows adding extra HTML attributes to the link.content
– Sets the displayed text of the link.
Examples and Usage
Basic example – A straightforward usage of the ‘aiterms’ shortcode to display a link to the ‘Terms’ page.
[aiterms /]
Advanced examples
Using the ‘aiterms’ shortcode with the ‘edit_tag’ attribute. This allows you to add additional HTML tags to the link. For example, you can add a class to style the link.
[aiterms edit_tag="class='my-class'" /]
Another advanced usage of the ‘aiterms’ shortcode is to override the link text. By default, the link text is ‘Terms’, but you can change it to anything you like.
[aiterms]Read our terms and conditions[/aiterms]
Note: Always ensure to properly escape any user-provided data within the shortcode attributes to prevent potential security issues.
PHP Function Code
In case you have difficulties debugging what causing issues with [aiterms]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'aiterms', 'aiwoo_shortcode_terms' );
Shortcode PHP function:
function aiwoo_shortcode_terms( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => ""
), $atts ) );
$edit_tag = esc_html( strip_tags( $edit_tag ) );
$href = get_permalink( wc_get_page_id( 'terms' ) );
$content = $content != '' ? $content : __( 'Terms' );
return '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [aimyaccount] Shortcode
The Aimyaccount shortcode is a WooCommerce plugin that generates a link to the ‘My Account’ page. This shortcode allows customization of the ‘My Account’ link text via the “edit_tag” attribute. It uses a PHP function to extract the shortcode attributes, sanitize the input, and return a clickable link.
Shortcode: [aimyaccount]
Parameters
Here is a list of all possible aimyaccount shortcode parameters and attributes:
edit_tag
– Optional HTML tag to edit the ‘Myaccount’ linkcontent
– Optional text for the ‘Myaccount’ link
Examples and Usage
Basic example – A simple shortcode that generates a link to the ‘My Account’ page.
[aimyaccount]
Advanced examples
Adding an ‘edit_tag’ attribute to the shortcode. This will allow you to add HTML tags to the shortcode output, such as class or id. This can be useful for styling the link with CSS.
[aimyaccount edit_tag="class='my-account-link'"]
Using the shortcode to display custom text for the ‘My Account’ link. By default, the link text is ‘Myaccount’, but you can change it by adding content within the shortcode.
[aimyaccount]Click Here to Access Your Account[/aimyaccount]
Combining both ‘edit_tag’ attribute and custom content within the shortcode. This example shows how you can fully customize the ‘My Account’ link with advanced parameters.
[aimyaccount edit_tag="class='my-account-link'"]Access Your Account Here[/aimyaccount]
PHP Function Code
In case you have difficulties debugging what causing issues with [aimyaccount]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'aimyaccount', 'aiwoo_shortcode_myaccount' );
Shortcode PHP function:
function aiwoo_shortcode_myaccount( $atts, $content = null ) {
global $woocommerce;
extract(shortcode_atts(array(
"edit_tag" => ""
), $atts ) );
$edit_tag = esc_html( strip_tags( $edit_tag ) );
$href = get_permalink( wc_get_page_id( 'myaccount' ) );
$content = $content != '' ? $content : __( 'Myaccount' );
return '<a href="' . esc_url( $href ) . '"' .$edit_tag . '>' . $content . '</a>';
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [aisearch] Shortcode
The ‘aisearch’ shortcode from the Woocommerce Menu Extension plugin is designed to embed a product search form into your WordPress site. This shortcode generates a search form that allows users to search specifically within your site’s product listings. The ‘button’ attribute can be customized to change the text displayed on the search button. By default, it says “Search”.
Shortcode: [aisearch]
Parameters
Here is a list of all possible aisearch shortcode parameters and attributes:
button
– Defines the text displayed on the search buttoncontent
– Sets the placeholder text in the search field
Examples and Usage
Basic example – A shortcode that triggers the WooCommerce product search form with a default “Search” button.
[aisearch /]
Advanced examples
1. Customizing the search button text:
By passing the “button” attribute to the shortcode, you can customize the text displayed on the search button. In the following example, the button text is set to “Find Products”.
[aisearch button="Find Products" /]
2. Customizing the search field placeholder:
You can also customize the placeholder text in the search field by passing a string as content to the shortcode. In the following example, the placeholder text is set to “Search for clothes…”.
[aisearch]Search for clothes...[/aisearch]
3. Combining both attributes:
Finally, you can combine both the “button” attribute and the content to fully customize the search form. In the following example, the button text is set to “Find Products” and the placeholder text to “Search for clothes…”.
[aisearch button="Find Products"]Search for clothes...[/aisearch]
PHP Function Code
In case you have difficulties debugging what causing issues with [aisearch]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'aisearch', 'aiwoo_shortcode_search' );
Shortcode PHP function:
function aiwoo_shortcode_search( $atts, $content = null ) {
global $woocommerce;
$atts = shortcode_atts(array(
"button" => "Search",
), $atts );
$content = $content != '' ? $content : __( 'Search Products…' );
$search = '<form action="'.esc_url( home_url( '/' ) ).'" class="woocommerce-product-search" method="get" role="search">
<input type="search" title="'.esc_attr_x( 'Search for:', 'label' ).'" name="s" value="'.get_search_query().'" placeholder="'.$content.'" class="search-field">
<input type="submit" value="'.$atts['button'].'">
<input type="hidden" value="product" name="post_type">
</form>';
return $search;
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
WooCommerce Menu Extension [aiproductcat] Shortcode
The ‘aiproductcat’ shortcode is used to display WooCommerce product categories. It has customizable attributes like “show_count”, “hierarchical”, “show_children_only”, “dropdown”, “hide_empty”, and “orderby”. This shortcode organizes the product categories based on the given attributes. If ‘show_children_only’ is set, it will only display the direct children of the current category. The ‘dropdown’ attribute allows the categories to be displayed in a dropdown format. The ‘hide_empty’ attribute hides categories with no products, while ‘orderby’ sorts them. You can use this shortcode to create a more structured and user-friendly product category display on your WooCommerce site.
Shortcode: [aiproductcat]
Parameters
Here is a list of all possible aiproductcat shortcode parameters and attributes:
show_count
– displays the number of products in each categoryhierarchical
– presents product categories in a hierarchical structureshow_children_only
– only displays child categories if set to 1dropdown
– generates a dropdown menu of product categories when set to 1hide_empty
– hides categories without products if set to 1orderby
– sorts categories by ‘order’ or ‘title’
Examples and Usage
Basic example – To display the product categories in a list format without showing the count of products in each category, use the following shortcode:
[aiproductcat show_count=0 /]
Advanced examples
To display the product categories in a hierarchical dropdown format with the count of products in each category, use the following shortcode:
[aiproductcat show_count=1 hierarchical=1 dropdown=1 /]
If you want to display only the children of the current product category in a list format, you can use the following shortcode:
[aiproductcat show_children_only=1 /]
To hide empty categories and order the categories by title, you can use the following shortcode:
[aiproductcat hide_empty=1 orderby="title" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [aiproductcat]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'aiproductcat', 'aiwoo_shortcode_productcat' );
Shortcode PHP function:
function aiwoo_shortcode_productcat( $atts, $content = null ) {
global $woocommerce, $wp_query, $post;
$atts = shortcode_atts(array(
"show_count" => 0,
"hierarchical" => 0,
"show_children_only" => 0,
"dropdown" => 0,
"hide_empty" => 0,
"orderby" => "order"
), $atts );
$c = $atts['show_count'];
$h = $atts['hierarchical'];
$s = $atts['show_children_only'];
$d = $atts['dropdown'];
$e = $atts['hide_empty'];
$o = $atts['orderby'];
$dropdown_args = array( 'hide_empty' => $e );
$list_args = array( 'show_count' => $c, 'hierarchical' => $h, 'taxonomy' => 'product_cat', 'hide_empty' => $e );
// Menu Order
$list_args['menu_order'] = false;
if ( $o == 'order' ) {
$list_args['menu_order'] = 'asc';
} else {
$list_args['orderby'] = 'title';
}
// Setup Current Category
$current_cat = false;
$cat_ancestors = array();
if ( is_tax( 'product_cat' ) ) {
$current_cat = $wp_query->queried_object;
$cat_ancestors = get_ancestors( $current_cat->term_id, 'product_cat' );
} elseif ( is_singular( 'product' ) ) {
$product_category = wc_get_product_terms( $post->ID, 'product_cat', array( 'orderby' => 'parent' ) );
if ( $product_category ) {
$current_cat = end( $product_category );
$cat_ancestors = get_ancestors( $current_cat->term_id, 'product_cat' );
}
}
// Show Siblings and Children Only
if ( $s && $current_cat ) {
// Top level is needed
$top_level = get_terms(
'product_cat',
array(
'fields' => 'ids',
'parent' => 0,
'hierarchical' => true,
'hide_empty' => false
)
);
// Direct children are wanted
$direct_children = get_terms(
'product_cat',
array(
'fields' => 'ids',
'parent' => $current_cat->term_id,
'hierarchical' => true,
'hide_empty' => false
)
);
// Gather siblings of ancestors
$siblings = array();
if ( $cat_ancestors ) {
foreach ( $cat_ancestors as $ancestor ) {
$ancestor_siblings = get_terms(
'product_cat',
array(
'fields' => 'ids',
'parent' => $ancestor,
'hierarchical' => false,
'hide_empty' => false
)
);
$siblings = array_merge( $siblings, $ancestor_siblings );
}
}
if ( $h ) {
$include = array_merge( $top_level, $cat_ancestors, $siblings, $direct_children, array( $current_cat->term_id ) );
} else {
$include = array_merge( $direct_children );
}
$dropdown_args['include'] = implode( ',', $include );
$list_args['include'] = implode( ',', $include );
if ( empty( $include ) ) {
return;
}
} elseif ( $s ) {
$dropdown_args['depth'] = 1;
$dropdown_args['child_of'] = 0;
$dropdown_args['hierarchical'] = 1;
$list_args['depth'] = 1;
$list_args['child_of'] = 0;
$list_args['hierarchical'] = 1;
}
// Dropdown
if ( $d ) {
$dropdown_defaults = array(
'show_counts' => $c,
'hierarchical' => $h,
'show_uncategorized' => 0,
'orderby' => $o,
'selected' => $current_cat ? $current_cat->slug : ''
);
$dropdown_args = wp_parse_args( $dropdown_args, $dropdown_defaults );
//wc_product_dropdown_categories( apply_filters( 'woocommerce_product_categories_widget_dropdown_args', $dropdown_args ) );
$current_product_cat = isset( $wp_query->query['product_cat'] ) ? $wp_query->query['product_cat'] : '';
$terms = get_terms( 'product_cat', apply_filters( 'wc_product_dropdown_categories_get_terms_args', $dropdown_args ) );
if ( ! $terms ) {
return;
}
$content = $content != '' ? $content : __( 'Select a category' );
$cat_drop = "<select name='product_cat' class='dropdown_product_cat'>";
$cat_drop .= '<option value="" ' . selected( $current_product_cat, '', false ) . '>' . $content . '</option>';
$cat_drop .= wc_walk_category_dropdown_tree( $terms, 0, $dropdown_args );
$cat_drop .= "</select>";
wc_enqueue_js( "
jQuery('.dropdown_product_cat').change(function(){
if(jQuery(this).val() != '') {
location.href = '" . home_url() . "/?product_cat=' + jQuery(this).val();
}
});
" );
return $cat_drop;
// List
} else {
$list_args['echo'] = 0;
$list_args['title_li'] = '';
$list_args['pad_counts'] = 1;
$list_args['show_option_none'] = __('No product categories exist.', 'woocommerce' );
$list_args['current_category'] = ( $current_cat ) ? $current_cat->term_id : '';
$list_args['current_category_ancestors'] = $cat_ancestors;
$content = $content != '' ? $content : __( 'Product Categories' );
$cat_list = '<h2 class="categories-title">'.$content.'</h2>';
$cat_list .= '<ul class="product-categories">';
$cat_list .= wp_list_categories( apply_filters( 'woocommerce_product_categories_widget_args', $list_args ) );
$cat_list .= '</ul>';
return $cat_list;
}
}
Code file location:
woocommerce-menu-extension/woocommerce-menu-extension/include/frontend.inc.php
Conclusion
Now that you’ve learned how to embed the WooCommerce Menu Extension Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply