-
AuthorPosts
-
October 12, 2023 at 12:03 am #1422167
Hello,
I would like to add the submenu shown on this page – https://wordpress-225877-3679670.cloudwaysapps.com/ to the individual woocommerce product pages. Is there a way to achieve this?
October 12, 2023 at 7:27 am #1422200Hey bbertuzzi7,
Thank you for the inquiry.
You can use a template hook to insert additional content in the product pages.
Example:
function ava_woocommerce_before_main_content() { if ( is_product() ) { echo do_shortcode('[av_breadcrumbs]'); } } add_action( 'woocommerce_before_main_content', 'ava_woocommerce_before_main_content', 10 );
To insert the same submenu, you can extract the element’s shortcode and then use it as the value for the do_shortcode function above. First, to extract the shortcode, you need to set the builder to debug mode.
// https://kriesi.at/documentation/enfold/intro-to-layout-builder/#debug-mode
Once debug mode is enabled, you’ll find the shortcode field below the Advanced Layout Builder. Simply copy the submenu shortcode and paste it as the value for the do_shortcode function above.
Best regards,
IsmaelOctober 12, 2023 at 2:41 pm #1422235Thank you. I have enabled debug mode and I see the shortcode for the sub menu. My question is, where do I put that template hook? In the functions.php or in the single page template for a woocommerce product? I am also confused as to how much of the shortcode to put into the function. In debug mode, this is the shortcode that I see:
[av_submenu which_menu='' menu='49' position='left' sticky='aviaTBsticky' color='alternate_color' mobile='disabled' mobile_switch='av-switch-768' alb_description='' id='' custom_class='' template_class='' av_uid='av-lnbxc8ss' sc_version='1.0']
[av_submenu_item title='Menu Item 1' button_style='' link='' linktarget='' av_uid='av-fdyw7' sc_version='1.0']
[av_submenu_item title='Menu Item 2' button_style='' link='' linktarget='' av_uid='av-70t2n' sc_version='1.0']
[/av_submenu]Should I be grabbing all of that shortcode and adding it to the function?
October 13, 2023 at 4:56 am #1422324Hi,
Thank you for the update.
You have to copy the whole av_submenu shortcode including av_submenu_item and use it as the value of the do_shortcode function. The snippet should go to the functions.php file, preferably in the child theme.
Best regards,
IsmaelOctober 13, 2023 at 5:55 pm #1422423This is the code that I inserted into the functions.php it caused a critical error on my site:
/**
* add submenu to product pages
*/
function ava_woocommerce_before_main_content() {
if ( is_product() ) {
echo do_shortcode(‘[av_submenu which_menu='' menu='49' position='left' sticky='aviaTBsticky' color='alternate_color' mobile='disabled' mobile_switch='av-switch-768' alb_description='' id='' custom_class='' template_class='' av_uid='av-lnbxc8ss' sc_version='1.0']
[av_submenu_item title='Menu Item 1' button_style='' link='' linktarget='' av_uid='av-fdyw7' sc_version='1.0']
[av_submenu_item title='Menu Item 2' button_style='' link='' linktarget='' av_uid='av-70t2n' sc_version='1.0']‘);
}
}
add_action( ‘woocommerce_before_main_content’, ‘ava_woocommerce_before_main_content’, 10 );Can you please let me know where the issue is? I’m just learning PHP and am not sure where the error is at. Thank you.
October 14, 2023 at 8:05 pm #1422487Hi,
Please note that your shortcode is using single quote marks:
so you need to use a double quote marks after echo do_shortcode( that wrap the inner shortcode:
and you can’t have any line breaks, try this code:function ava_woocommerce_before_main_content() { if ( is_product() ) { echo do_shortcode("[av_submenu which_menu='' menu='49' position='left' sticky='aviaTBsticky' color='alternate_color' mobile='disabled' mobile_switch='av-switch-768' alb_description='' id='' custom_class='' template_class='' av_uid='av-lnbxc8ss' sc_version='1.0'][av_submenu_item title='Menu Item 1' button_style='' link='' linktarget='' av_uid='av-fdyw7' sc_version='1.0'][av_submenu_item title='Menu Item 2' button_style='' link='' linktarget='' av_uid='av-70t2n' sc_version='1.0']"); } } add_action( 'woocommerce_before_main_content', 'ava_woocommerce_before_main_content', 10 );
Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
Best regards,
Mike -
AuthorPosts
- You must be logged in to reply to this topic.