Tagged: custom menu, woocommerce
-
AuthorPosts
-
March 8, 2015 at 8:09 am #407634
Hi there,
Is there a way to add some php to the single-content.php in woo to display a custom menu?
I build separate pages for my products and I don’t want single product to be linked to categories but to custom subpages :Food (page) –> Drinks (subpage), Meat (subpage).
I duplicated the content-single-product.php and single-product.php and created content-single-product-food.php and single-product-food.php
I’d like to call for a custom menu on content-single-product-food.php
I can deal with styling myself but how to add the custom menu I created for FOOD.
Thanks!
March 9, 2015 at 3:23 pm #408151Hi Smaskit6!
Thank you for using Enfold.
You can use woocommerce hooks and filters to insert a new element such as a drop down menu inside a single product page. Maybe, you can use the Fullwidth Sub Menu shortcode and the do_shortcode function. Refer to this link for more info: http://docs.woothemes.com/document/hooks/
Cheers!
IsmaelMarch 9, 2015 at 11:21 pm #408532Ismael,
Thanks much! It shows up but messes up the styling and even some layout on woo single.
I added this : <?php echo do_shortcode(‘[av_submenu menu="781" position="center" color="main_color" sticky="aviaTBsticky" custom_class=""]‘); ?>
to my custom content-single-product-food.php
<?php
if ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly
?>
<?php echo do_shortcode(‘[av_submenu menu="781" position="center" color="main_color" sticky="aviaTBsticky" custom_class=""]‘); ?>
<?php
/**
* woocommerce_before_single_product hook
*
* @hooked wc_print_notices – 10
*/
do_action( ‘woocommerce_before_single_product’ );if ( post_password_required() ) {
echo get_the_password_form();
return;
}
?>Should I add something to CLEAR it so it does not affect the styling/layout (4 columns become 3) on single product?
March 10, 2015 at 11:31 pm #409603Hey!
If you don’t need a full width menu i’d suggest using wp_nav_menu instead (if you need an example on how to use check includes/helper-main-menu.php:130).
Regards,
JosueMarch 11, 2015 at 8:30 pm #410078Hi Ismael,
I’m so lost..
I feel like it should be easy but it’s not.The menu on single custom category items stopped showing up so I need to redo it.
Questions :
1. I read I should copy the woocommerce folder from plugins to theme and this is where I would overwrite the behavior.
Is it where I should be doing it instead of woocommerce/plugins/templates ?2. Can you walk me through HOW TO DISPLY the menu (full width or not, don’t care..) on my custom single products?
So, if I have a custom page : FOOD and I want to display that custom menu on single FOOD items how would I do it…?
What php code on which template?I’m really confused. I know you don’t have to help out with woo but I’d so appreciate it!
Thanks much!March 11, 2015 at 11:45 pm #410200So, I’m trying…
I’ve decide to add this to : woocommerce/template/single-product.php
<?php while ( have_posts() ) : the_post(); ?>
<?php
if (is_product(‘Food’)) {
wc_get_template_part ( ‘content’, ‘single-product-food’ );
}else{
wc_get_template_part ( ‘content’, ‘single-product’ );
} ?>
<?php endwhile; // end of the loop. ?>and this to : woocommerce/template/content-single-product-food.php
<?php
if ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly
?>
<div class=”singlefoodsmenu”>
<?php wp_nav_menu( array(‘menu’ => ‘Cards’ )); ?>
</div>
——
The menu shows up on all categories… not just Food
if (is_product(‘Food’)) {How do I state this on woocommerce/template/single-product.php
so my content from contact-single-product-foods.php (or whatever category) shows up on single categories I choose instead on all…ps. This is just me testing with minimal php knowledge.
If you have an idea (Josue, Ismael) how to do it properly, please let me know. Thanks much!March 12, 2015 at 3:14 am #410258Hi,
Can you post the link to your website please? admin access may be needed too.
Regards,
JosueMarch 12, 2015 at 3:37 am #410264This reply has been marked as private.March 12, 2015 at 10:50 am #410382Hi!
I didn’t find any “food” category on the website you posted, can you point where exactly it is?
Best regards,
JosueMarch 12, 2015 at 4:24 pm #410545This reply has been marked as private.March 12, 2015 at 7:10 pm #410659Hey!
Use this (put in functions.php):
function add_menus_to_single_products() { if( has_term('Cards', 'product_cat') ){ wp_nav_menu( array('menu' => 'Cards Menu' )); }elseif( has_term('Music', 'product_cat') ){ wp_nav_menu( array('menu' => 'Music Menu' )); }elseif( has_term('Books', 'product_cat') ){ wp_nav_menu( array('menu' => 'Books Menu' )); }else{ } } add_action('woocommerce_before_single_product', 'add_menus_to_single_products');
That’s a hook to the single product view that will render a specific menu if that product is in a certain category.
Regards,
JosueMarch 12, 2015 at 7:28 pm #410674You’re a genius, Josue! Thanks a million!!!! :))))
Have a great day!March 12, 2015 at 8:59 pm #410728You are welcome, always glad to help :)
Regards,
JosueMarch 13, 2015 at 12:00 am #410784This reply has been marked as private.March 13, 2015 at 12:01 am #410785This reply has been marked as private.March 13, 2015 at 12:02 am #410787This reply has been marked as private.March 13, 2015 at 2:53 am #410811Hi,
Can you please create me a temporary FTP account or enable file editing from the Dashboard?
Regards,
JosueMarch 13, 2015 at 3:04 am #410812This reply has been marked as private.March 13, 2015 at 4:09 am #410822Hey!
The code is working as expected, you needed to clear the cache and change the code, you need to change each category and set their respective menus (and repeat as needed):
function add_menus_to_single_products() { if( has_term('cards', 'product_cat') ){ wp_nav_menu( array('menu' => 'Cards Menu', 'container_class' => 'single_product_menu' )); }elseif( has_term('music', 'product_cat') ){ wp_nav_menu( array('menu' => 'Pixia Main Menu', 'container_class' => 'single_product_menu' )); }elseif( has_term('books', 'product_cat') ){ wp_nav_menu( array('menu' => 'Books Menu', 'container_class' => 'single_product_menu' )); }else{ } } add_action('woocommerce_before_single_product', 'add_menus_to_single_products');
Here’s this product for example (which is under Music), you’ll see that the Pixia Main menu shows (as set in the code).
Regards,
Josue- This reply was modified 9 years, 8 months ago by Josue.
March 13, 2015 at 4:40 am #410828This reply has been marked as private.March 13, 2015 at 4:41 am #410830Aaaa…thank you thank you Josue! So much.
You’ve been incredibly helpful and the support is amazing!March 13, 2015 at 10:46 am #410896You are welcome, glad to help :)
Best regards,
Josue -
AuthorPosts
- You must be logged in to reply to this topic.