WooCommerce list view - wordpress

I have a WordPress site with WooCommerce installed,
The problem I'm having is on the shop page the products are by default shown as a GRID (side by side), there's a button to switch from the default GRID mode to LIST mode; but for every new client that comes on the site, they would have to manually change it!
I'd like to permanently change the default view from GRID to LIST for every person that comes on the site, but I can't find any way to do this in the code.
Does anyone have any knowledge on how to do this?

There is a plugin that can do this for you: http://wordpress.org/plugins/woocommerce-grid-list-toggle
After installing the plugin go to your dashboard: Woocommerce -> Settings -> product -> Scroll to the bottom of the page and there is an option called Default catalog view, change that from Grid to List.
There will be an option for users on the shop page to change the view from List to Grid. To hide this option add the following to the CSS:
.gridlist-toggle
{
display: none !important;
}

My solution can switch grid to list view as default on products page.
You can try this:
Connect to your FTP/public_html/wp-content/YOUR_THEME/woocommerce/global/
Edit wrapper-start.php
You will see this code
$shop_view = shopme_get_meta_value('shop_view');
if (empty($shop_view)) { $shop_view = 'view-grid'; }
if (!empty( $shop_view ) ) { $wrapper_classes[] = $shop_view; }
Replace "view-grid" to "list_view_products"

I just solved the same problem.
This is my solution how to PERNAMENTLY force WooCommerce to show product catalog only as List View.
JS
// This will remove class="grid" on page load and add class="list" to your product view
$(document).ready(function(){
$('.browse-view ul#products').removeClass('grid').addClass('list');
});
JS -- Test with Woocommerce v4.0.1
// -- Last Rev. (2020-04) --
jQuery(function($){
$('.woocommerce ul.products').removeClass('grid').addClass('list');
});
CSS
/* This will hide grid/list switcher in toolbar*/
.view-mode{display:none!important;}

Another way to do this is use this plugin: https://wordpress.org/plugins/gridlist-view-for-woocommerce/
After install go to settings WooCommerce -> Grid/List View
In Buttons tab change Default style to List and uncheck all in Buttons display
In Products Count tab uncheck Use products count

Related

Add orderby="rand" function in wpbakery Wordpress

I have a theme for an eCommerce website and my homepage is built with wpbakery. Products displayed in the homepage are not changing after refresh. All the products are in the same place. I found no option in wpbakery elements to change order by random. How can I add this functionality?
I am sure in wpbakery there is a way you can do this by selecting a random option. But if you are unable to find it check and see if this works in your case.
add_action('pre_get_posts', 'my_pre_get_posts');
function my_pre_get_posts($query) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set('orderby', 'rand');
}
}
Put the code in your function file. It will set your homepage post orderby rand. Hope it works but I advise you to follow WPbakery setting to do that.
Simple Steps to find your way in WPbakery
make sure your plugin is active
Go to the page set as your homepage and click on edit page
open the post setting in the wpbakery
Select Data setting
Choose the first option which is "Order by"
scroll down and select "Random order" and save your setting.
That should point you to the right way to set random post order in WPbakery.

Remove sub menus from the admin view for a plugin that registers a custom post type

I know there are 357,982 other posts about this BUT they all kinda lack something ie. an actual example that works for those of us who don't write 4,594,334 line of code every day.
SO - As it stands the scenerio is:
A plugin that registers a custom post type
A sub-menu you want to hide
What next?
The best solution I have found is actually pretty easy and requires a bit of inspection of the source and a good understanding of what to look for.
In this example woocommerce is registering the custom post type 'product' with a sub-menu that appears as 'Product Options'. We want to hide this for non-admin users.
Doing an inspection of the menu items we find that the hyperlink for the parent menu is 'edit.php?post_type=event_ticket' - looking a little further we see that the hyperlink for the sub-menu is 'https://websitename.com/wp-admin/edit.php?post_type=product&page=product_attributes'
We will use the 'add_action' hook as shown below. Please note that we are using the url for the parent menu however we are ONLY using the page parameter for the child.
add_action('admin_menu', 'remove_menu_pages', 999);
function remove_menu_pages()
{
if (current_user_can('manage_options') == false)
{
//1st parameter is parent URL | second is the 'page' parameter from the child url
remove_submenu_page('edit.php?post_type=product', 'product_attributes');
}
}
Add this to your functions.php and then login as a non-admin user and the submenu should now be hidden.

Change a homepage based on theme wordpress

I have 2 themes in my WP installation: Theme, Theme2, and separately I have 2 Homepages, one for each theme.
Is it any way for me to change a homepage based on active theme dynamically?
So, Example if i'll activate Theme2, Homepage2 becomes a main homepage?
Ideally, i want something like:
if ( current_user_can( 'manage_options' ) ) {
switch_theme('twentytwelve');
/* Activate Homepage_1 */
} else {
switch_theme('twentythirteen');
/* Activate Homepage_2 */
}
}
Change a homepage based on theme wordpress
You can follow this steps and set the homepage page as you have activated the theme.
Click on “Pages” from your dashboard.
Click the “Add New” button on the top and create a new page called, “Homepage.”
Go to “Settings” from the dashboard, and click on “Reading.”
The first option available is called “Front Page Displays.” Change it to “A static page.”
In the “Front Page” drop down, you should see your new homepage. Select it and save your changes.
Go back into “Pages” and click on your homepage.
Add the shortcodes you want to display.
Update your homepage.

Removing certain links in admin header bar added by plugins

I have instaled several plugins and they tend to add links on the admin bar that is
I have ultimate affiliate pro and it has added new and referral affiliate and other plugins like ithemes security has a link on the admin bar such that now my admin bar looks mesed up like in the image below
How can i edit this is there a plugin which can remove certain links on the admin dashboard bar without having to disable the plugins
I have tried:
checking on the screen options but there is no way to uncheck links
Here is the example of how you can remove the unwanted links from admin_bar.
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wporg'); // Remove the WordPress.org link
$wp_admin_bar->remove_menu('documentation'); // Remove the WordPress documentation link
$wp_admin_bar->remove_menu('support-forums'); // Remove the support forums link
$wp_admin_bar->remove_menu('feedback'); // Remove the feedback link
$wp_admin_bar->remove_menu('w3tc'); // If you use w3 total cache remove the performance link
$wp_admin_bar->remove_menu('my-account'); // Remove the user details tab
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
You need to check the menu name and add it to the function call via add_action.

Get a node to show up underneath a View's menu item

So I've got a content type of "News" and then a View which shows a list of News nodes as a menu item.
Is there any way to highlight the News View in the menu tree when you're viewing a News node?
I'm sort of aware of why this doesn't work, and why doing this might be hacky, but there's got to be a way to have a "default" menu item or something that a node can show up under.
Actually, I found a module that does basically what the template.php answer above does, by allowing you to assign a default menu item by content type.
It's called Menu Trails. Here is an excerpt from its project page:
... adds some common-sense usability to Drupal's menu system
Menu Trails implements primary/secondary links which keep the current menu trail "active" or highlighted. A handy snippet ready to go into your template.php is included.
The module provides a means of broadly categorizing nodes (by type or taxonomy) as falling "under" a known menu item. These nodes are not added to the menu tree (keeping the menu admin system sane) but they will trigger the functionality above -- preserving navigation state for the user -- when viewed.
New for 6.0: Menu Trails can also set breadcrumbs for nodes, keeping them in sync with the trail.
New for 6.0: Menu Trails is now Organic Groups aware, so nodes can be designated to fall "under" the first group node they belong to.
New for 6.0: A token is exposed to pathauto (and other token-aware modules) allowing for the menu trail to be used in automatic path alias creation.
Assuming the answer to my above comment is "yes," this is something you can accomplish through the template.php file in your theme folder
The final solution will depend on your settings, but generally most of the action will happen inside phptemplate_preprocess_page
// Simplified, and untested in this form
function phptemplate_preprocess_page(&$vars) {
if (isset($vars['node'])) { // if we're looking at a node
$body_classes[] = (($vars['node']->type == 'News') || (arg(0) == 'News')) ? 'news_page' : ''; // Page is news page
}
else if (arg(0) == 'taxonomy') {
// ... Special handling for news taxonomy pages, if you want
} else {
$body_classes[] = "page-type-" . arg(0);
}
$body_classes = array_filter($body_classes); // Out! Out! Damn empty elements!
$vars['body_classes'] = implode(' ', $body_classes);
}
This will give the you the body.news_page style class to work with, and you can combine that with the style of your news menu block to make it appear how you like.
if Menutrails doesn't work (for me it didn't) you can do it yourself by something like:
$somenode = menu_get_item('node/5');
menu_set_item($somenode);
I have found you have more control if you do something like this in hook_nodeapi().
// this code worked for me
$somenode = menu_get_item();
$somenode['href'] = 'node/5';
menu_set_item(NULL, $somenode);
You may need to set the weight of your custom module to be heavier than core modules: at least 1

Resources