Remove the Sort by dropdown completely, in WooCommerce - woocommerce

I want to remove the Sort by dropdown completely, in my WooCommerce installation.
http://cswpstage.hostworks.net/product-category/memorabilia/signed-photos/
Thanks!

It depends on the theme that you're using. There are two approaches, CSS and PHP.
I see on your theme you have already hidden it via CSS using
.sort-param-order,
.sort-param-sort {
display: none;
}
If you want to hide it with PHP, you need to look for the action which adds it and remove that action. A search for woocommerce_catalog_ordering will generally return the action you're looking for.
Here is how you remove it via standard WooCommerce:
<?php
/**
* Remove sorting from WooCommerce.
*/
function thenga_remove_filtering() {
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
}
add_action( 'init', 'thenga_remove_filtering' );
And here is how you remove it from the Storefront theme:
<?php
/**
* Remove sorting from Storefront.
*/
function thenga_remove_filtering() {
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );
}
add_action( 'init', 'thenga_remove_filtering' );

Related

Moving Woocommerce Order Review to Top of Checkout

I'm trying to move the order review section to the top of Woocommerce checkout page and this is working:
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
add_action( 'woocommerce_before_checkout_form', 'woocommerce_order_review', 20 );
But when Checkout opens it scrolls down to the order review section, rather than to the top of the page.
This works:
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
add_action( 'woocommerce_after_checkout_billing_form', 'woocommerce_order_review', 20 );
Moving the review form doesn't automatically move the Your Order heading. This is what I added to functions.php
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
add_action( 'woocommerce_before_checkout_form', 'prefix_wc_order_review_heading', 3 );
add_action( 'woocommerce_before_checkout_form', 'woocommerce_order_review', 4 );
/**
* Add a heading for order review on checkout page.
* This replaces the heading added by WooCommerce since order review is moved to the top of the checkout page.
*/
function prefix_wc_order_review_heading() {
echo '<h3>Your Order</h3>';
}
And to hide the existing Your Order heading (and some spacing for the credit card form), I added this to style.css
.woocommerce-checkout #order_review_heading {
display: none !important;
}
.woocommerce-checkout #order_review {
margin-top: 2rem !important;
}

Remove breadcrumbs from WooCommerce Storefront theme

In order to remove breadcrumbs from the Storefront theme, the documentation states to add the following in functions.php:
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
I tried this in a child theme of Storefront and it doesn't work. Tracing back the woocommerce_breadcrumb, it seems to be added in storefront_content_top action (in the file <storefront_dir>/inc/woocommerce/storefront-woocommerce-template-hooks.php. I commented out the corresponding line and indeed the breadcrumbs are hidden.
However, to do this the right way, I try to disable it from the child theme using
remove_action( 'storefront_content_top', 'woocommerce_breadcrumb', 10 );
but it doesn't work. I should clarify that I test this in a fresh child theme with no other code.
How would one disable the breadcrumbs from a child theme?
Copy and paste the following snippet into your functions.php file.
add_action( 'init', 'z_remove_wc_breadcrumbs');
function z_remove_wc_breadcrumbs() {
remove_action( 'storefront_before_content', 'woocommerce_breadcrumb', 10);
}
since Storefront 2.3.1 try this
add_action('init', 'dp_remove_wc_breadcrumbs');
function dp_remove_wc_breadcrumbs(){
remove_action('storefront_before_content', 'woocommerce_breadcrumb', 10);
};
Try this:
add_filter( ‘woocommerce_get_breadcrumb’, ‘__return_false’ );
remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
.breadcrumb{
display: none;
}

remove_action on related products is not working with woocommerce hook

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
I have this line in my functions.php file. I got these hooks from the content-single-product.php file. However, the related products on my single product page still exists.
I don't want to remove the functionality entirely, I duped their $args to do my own query.
Updated
function remove_woo_relate_products(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
}
add_action('init', 'remove_woo_relate_products', 10);
I tried to write a function to achieve my goal, but the related products from the do_action is still present. I can only think of CSS to do what I need, but I shouldn't have to rely on this.
Also, just for the sake of showing this, this is what's in the content-single.product.php file:
<?php
/**
* woocommerce_after_single_product_summary hook.
*
* #hooked woocommerce_output_product_data_tabs - 10
* #hooked woocommerce_upsell_display - 15
* #hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
As LoicTheAztec correctly pointed out, your code is working fine. We tested it. The related products were removed but the upsell products were still there.
We tested using storefront theme.
function remove_woo_relate_products(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
remove_action( 'woocommerce_after_single_product_summary', 'storefront_upsell_display', 15 );
}
add_action('init', 'remove_woo_relate_products', 10);
You can see that storefront_upsell_display is calling the woocommerce_upsell_display
function storefront_upsell_display() {
woocommerce_upsell_display( -1, 3 );
}
So in this code, we have removed the theme's action for upsell. In the same logic, there is a possibility that related products function may be called in your theme. If this is the case you can remove the corresponding action for that.
Note: Make sure the code is in your current theme's functions.php

Remove 'Theme Options' Option Tree Wordpress

I use the Options Tree. Just to use a Meta Box only. And I do not use his Theme Options.
In the picture below, how to throw Theme Options menu?
Is it possible?
Add the following code to your functions.php file:
function remove_ot_menu () {
remove_submenu_page( 'themes.php', 'ot-theme-options' );
}
add_action( 'admin_init', 'remove_ot_menu' );
This will remove the panel you want to remove.
/**
* Option Tree Files
* Including Files and setting up Option Tree
*
* #Since 1.0.0
* Version 1.0.0
*/
if(class_exists('OT_Loader' )):
//Filter for option tree settings
add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_show_new_layout', '__return_false' );
add_filter( 'ot_post_formats', '__return_true');
add_filter( 'ot_use_theme_options', '__return_false' ); //This filter removes theme options page.
endif;
The code above is helpful to remove custom Theme options page from Option Tree, make sure you add this in functions.php
This code is helpful for people who want to just use Metaboxes of OptionTree plugin not the Theme options.

WordPress remove admin menu item

Generally it's not a problem to remove wp-admin menu items, e.g:
add_action( 'admin_init', 'my_remove_menu_pages' );
function my_remove_menu_pages() {
remove_submenu_page( 'themes.php', 'theme-editor.php' );
}
However I'm currently struggling with the following page:
admin.php?page=wpml-string-translation/menu/string-translation.php
What's the best method to have this one removed?
I think you're add_action needs a numeric as a 3rd argument (a priority).
https://wordpress.stackexchange.com/questions/55581/how-can-i-remove-the-wp-menu-from-the-admin-bar
Example
If you have this add_action:
add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
To remove it, it needs a higher priority (11):
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: Remove WP Menu From Tool Bar
*/
if ( ! function_exists( 't5_remove_wp_menu' ) )
{
// The action is added with a priority of 10, we take one step later.
add_action( 'init', 't5_remove_wp_menu', 11 );
/**
* Remove the WP menu action.
*/
function t5_remove_wp_menu()
{
is_admin_bar_showing() &&
remove_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
}
}
Based on the previous answers, here's the completed solution for both WPML user menus:
function remove_menu_items()
{
//removes the 'String Translation' menu item from editor's admin screen
if (defined('WPML_ST_FOLDER')){
remove_menu_page(WPML_ST_FOLDER.'/menu/string-translation.php');
}
//removes the 'Translation Interface' menu item from editor's admin screen
if (defined('WPML_TM_FOLDER')){
remove_menu_page(WPML_TM_FOLDER . '/menu/translations-queue.php');
}
}
add_action('admin_menu', 'remove_menu_items', 999);
This should work,
add_action( 'admin_init', 'my_remove_menu_pages' );
function my_remove_menu_pages() {
remove_submenu_page( 'admin.php?page=wpml-string-translation/menu/string-translation.php', 'admin.php?page=wpml-string-translation/menu/string-translation.php' );
}
The working solution:
function remove_menu_items()
{
//removes the String Translation menu item from editor's admin screen
if (defined('WPML_ST_FOLDER'))
remove_menu_page(WPML_ST_FOLDER.'/menu/string-translation.php');
}
add_action('admin_menu', 'remove_menu_items', 999);
It needs a higher priority from which it was created and to avoid any issues let's use the same WPML constant, which we can find on the file "wpml-string-translation-class.php" at the plugin folder, line 212 as of version 1.6.1 of the WPML String Transtation plugin.

Resources