1

I am modifying a Theme I purchased since it is not prepared for woocommerce. It has an option to select a megamenu from a dropdown list on the menu where it says not megamenu.

megamenu

This is the code I find related to this part of the menu on my theme code.

$menu_control .= '<select style="'. $style .'" name="penci_cat_mega_menu[' . $item->ID . ']" id="" class="widefat code edit-menu-item-url">';
        foreach ( $td_category_tree as $category => $category_id ) {
            $menu_control .= '<option value="' . $category_id . '"' . selected( $penci_cat_mega_menu, $category_id, false ) . '>' . $category . '</option>';
        }

I want it to not only display categories, but also woocommerce categories on this menu styling preset. How can I add this to this dropdown menu?

function penci_wp_update_nav_menu_item( $menu_id, $menu_item_id, $args ) {

    // Update meta menu items
    if ( isset( $_POST['penci_cat_mega_menu'][$menu_item_id] ) ) {
        update_post_meta( $menu_item_id, 'penci_cat_mega_menu', $_POST['penci_cat_mega_menu'][$menu_item_id] );
    }
    if ( isset( $_POST['penci_number_mega_menu'][$menu_item_id] ) ) {
        update_post_meta( $menu_item_id, 'penci_number_mega_menu', $_POST['penci_number_mega_menu'][$menu_item_id] );
    }

}

function hook_wp_nav_menu_objects( $items, $args = '' ) {
    $menu_items = array();

    foreach ( $items as &$item ) {
        $item->is_mega_menu = false;

        // if menu is mega menu, render mega menu
        $penci_catid_mega_menu = get_post_meta( $item->ID, 'penci_cat_mega_menu', true );
        $penci_number_mega_menu = get_post_meta( $item->ID, 'penci_number_mega_menu', true );
        if( ! isset( $penci_number_mega_menu ) || empty ( $penci_number_mega_menu ) ): $penci_number_mega_menu = '1';  endif;

        if ( ! empty( $penci_catid_mega_menu ) ) {

            $item->classes[] = 'penci-mega-menu';

            // add the parent menu
            $menu_items[] = $item;

            // create mega menu item
            $post                 = new stdClass;
            $post->ID             = 0;
            $post->post_author    = '';
            $post->post_date      = '';
            $post->post_date_gmt  = '';
            $post->post_password  = '';
            $post->post_type      = 'menu_penci';
            $post->post_status    = 'draft';
            $post->to_ping        = '';
            $post->pinged         = '';
            $post->comment_status = get_option( 'default_comment_status' );
            $post->ping_status    = get_option( 'default_ping_status' );
            $post->post_pingback  = get_option( 'default_pingback_flag' );
            $post->post_category  = get_option( 'default_category' );
            $post->page_template  = 'default';
            $post->post_parent    = 0;
            $post->menu_order     = 0;
            $new_item             = new WP_Post( $post );

            /*
             * if this is mega menu
             * set the is_mega_menu flag
             * render content of this mega menu
             */
            $new_item->is_mega_menu = true; // sent to the menu walkers

            $new_item->menu_item_parent = $item->ID;

            $new_item->url   = '';
            $new_item->title = '';
            $new_item->title .= '<div class="penci-megamenu">';
            $new_item->title .= penci_return_html_mega_menu( $penci_catid_mega_menu, $penci_number_mega_menu );
            $new_item->title .= '</div>';

            $menu_items[] = $new_item;

        }
        else {
            $menu_items[] = $item;
        }
    } //end foreach

How can I also display woocommerce categories and make this work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.