WooCommerce: How to hide/remove the category under the product title in the shop page? - wordpress

I would like to hide or remove the category meta from the shops page (catalogue
) which is showing right under the product title in my store. I have tried several things but nothing works.
I tried CSS:
.product__categories {display:none!importamt;}
and this...
.product_meta .sku_wrapper {
display:none!important;
}
.product_meta .posted_in {
display:none!important;
}
I tired this in functions too remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
How can I hide the category meta?

I used this:
.product-details .posted_in { display: none; }
and it worked for me
The .product_meta class you are trying to use is not on the catalogue page - it is on the product detail page.

This is an old question, but you might try
remove_action('woocommerce_after_single_product_summary',
'woocommerce_template_single_meta', 40);
in a theme (like in functions.php) or a code snippet.
The PHP solution should be slightly better because it changes the page before delivering it, rather than still serving the meta section and including some CSS instructions to not display it.
This works in WC 6.7.0. If it doesn't work, perform a search in the WooCommerce plugin for the exact lettering, woocommerce_template_single_meta (You can do this by loading the folder into something like Sublime Text.), and adjust accordingly. For example, if in the future, you find that it's added with add_action( 'woocommerce_random_action_why_was_this_changed', 'woocommerce_template_single_meta', 50 ); you need to use remove_action('woocommerce_random_action_why_was_this_changed', 'woocommerce_template_single_meta', 50);.
Update: This isn't working on my own site and I don't know why.
Another thing you can do to remove the product meta section is to create a file in your theme or child theme within a /woocommerce/single-product path called meta.php, i.e: yourawesometheme/woocommerce/single-product/meta.php. Give it this content:
<?php
if (!defined('ABSPATH')) exit;
This works consistently.
(I think you could leave the file completely blank, skipping the (!defined('ABSPATH')) part, but I'm not certain. Perhaps someone else could clarify.)

Related

Is there a better way to get dynamic CSS settings into a WP page?

I'm working on a plugin where I need some of the colors to be settable in the admin.
Right now, I have these color settings saved with the WP update_option() function. Then, when I need to display a page, I use the get_option() function then embed the color codes like this:
<style>
.some_class{ background-color: <?php echo $settings->color_code;?>; }
</style>
Of course, this works. But it seems a bit clumsy because the plugin can load one of several PHP based pages. So, for each one, I have to do the above.
Is there some way to get this tag into all my plugins pages without doing it page by page?
for frontend:
add_action( 'wp_enqueue_scripts', 'custom_css', 100 );
function custom_css(){
echo '<style>css here!</style>';
}
it should print after your current css stylesheets so it will override prev. css

Woocommerce - Move titles over thumbnails of products in Category page

I need to move the titles of the products, while I am browsing the category page, over their thumbnails
Details:
I have created a shop page where I only display the categories.
Every category contains 1 to 10 products.
Once I click a category, I land on a page where I see all of the products in that category.
I would like to see the titles of those products appearing over their thumbnails.
Thank you
A few more details relating to your parituclar setup are needed to give a proper answer. However, I'm going to assume you have everything at default. This is what you would need to add to the end of functions.php in your active theme folder:
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
For reference, check https://github.com/woothemes/woocommerce/blob/master/templates/content-product.php and https://github.com/woothemes/woocommerce/blob/master/includes/wc-template-hooks.php
If this does not work, check:
that you use the latest version of woocommerce. Actually a few versions back should work the same, but not too far back.
that your woocommerce templates are not overwritten. Check your theme folder for a file called content-product.php or in a subfolder woocommerce/content-product.php. If that has been altered, you need to adjust accordingly, perhaps by making changes right there.
that your theme does not already mess around with product display hooks. If it does, find out what's different.
Please note that this changes behavior for all woocommerce loops, such as any shortcodes you might be using and the "related products" section in single product view, if that is enabled. To affect only categories, the changes should be wrapped in a condition check ( is_product_category() ).
If you put code into a plugin, you must wait for WooCommerce loading:
add_action('plugins_loaded', function()
{
// move product's title before product thumbnail instead of next to that
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
add_action('woocommerce_before_single_product_summary', 'woocommerce_template_single_title');
}
Added this CSS for the product title and it worked fine for me. I used media query of course.
position: absolute;
top: 0px;

How do I remove Woocommerce sidebar from cart, checkout and single product pages?

Like many people that start using woocommerce for the first time I need to know how to customise it. In my particular situation I want to remove the sidebar from the Cart, Checkout and single product pages. My sidebar is defined and called from sidebar.php using the code below:
<?php dynamic_sidebar('global-sidebar'); ?>
I have tried for a long time to find an answer that works but I can't seem to find the correct code or solution. Perhaps asking the question myself will work. By the way I really appreciate the answers in the other articles and how-to's but they don't work for me.
Before I go any further I am using Bootstrap (latest version as of 2014) to style my Wordpress website. Not sure if that matters but maybe it does somehow.
Can someone please tell me how I find and then tell Woocommerce not to display any kind of sidebar on the Cart, Checkout and Single Product pages?
p.s.
The website can be found here > wp.wunderful.co.uk (staging site for a client website project)
Go to "Cart" page from dashboard pages, from "Page Attribute Section" -> "Templates" choose "Full Width" this will give you a page without sidebar.
In theory, something like the following ought to work, but I haven't tested it. (To be added to your theme's functions.php)
function so_25700650_remove_sidebar(){
if( is_checkout() || is_cart() || is_product() ){
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
}
}
add_action('woocommerce_before_main_content', 'so_25700650_remove_sidebar' );
If you look at the Woo templates you will see
<?php
/**
* woocommerce_sidebar hook
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action( 'woocommerce_sidebar' );
?>
This is Woo saying: "Display the sidebar here". But it is adding the woocommerce_get_sidebar function to the woocommerce_sidebar hook... which is convenient because it allows you to unhook that function like I've shown above. Finally, I am using Woo's conditional logic to only unhook the function from its action on the pages you requested.
I'm running my function on the woocommerce_before_main_content hook, which I think should work assuming your theme hasn't removed that hook. If so, then you could probably use wp_head or something that is guaranteed to be there, though then you'd probably want to check that the is_checkout(), etc functions exist or risk breaking your theme should you ever deactivate WooCommerce. As I have it, i should only run on WooCommerce-specific pages and so checking if the WooCommerce functions are defined is probably overkill.
Important Note:
This assumes the default theme or a theme that isn't running its own custom sidebar functions. If your theme is doing something else you will need to investigates its particular functions and templates.
What you should do is to create a files called woocomemrce.php in your theme if it doesn't already exists. Then you should look at your page template files for full width and for page with sidebar to see how they are structured and see where they differ.
Then copy the contents of one the files into woocommerce.php and replace the loop with woocommerce_content(), see this page for details.
Lastly see where the different page templates differ and then use if-statements in the places where they differ.
if( is_post_type_archive( 'product' ) ) :
//Content to display in the list view (i.e. with sidebar)
else :
//Content to display all other views (i.e. without sidebar)
endif;
.woocommerce-cart .sidebar {
display: none;
}
.woocommerce-cart .content-area {
width: 100%;
}
add this in custom/style.css.
From
https://wordpress.org/support/topic/remove-sidebar-for-woocommerce-cart-and-checkout-pages/
On your theme, likely subtheme, function.php
add_action('wp_head', 'hide_sidebar' ); function hide_sidebar(){ if(is_cart() || is_checkout()){ ?>
<style type="text/css">
#secondary {
display: none;
}
</style>
<?php
}
To remove sidebar from the Cart, Checkout and single product pages you want to use action hook in function.php file -
add_action('woocommerce_before_main_content', 'remove_sidebar' );
function remove_sidebar()
{
if( is_checkout() || is_cart() || is_product()) {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
}
Here you can get WooCommerce Action and Filter Hook
-https://docs.woothemes.com/wc-apidocs/hook-docs.html

How to remove shopping cart from WooCommerce plugin in Wordpress?

I'm using the Virtue Theme in Wordpress and have installed the WooCommerce plugin for setting up my online store. I want to remove the shopping cart function completely and instead place an order form on individual product page.
Help is sought to remove the shopping cart.
this is my experienced with Woocommerce about remove carts function. I added this code in functions.php in my Virtue themes.
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
In this Web I used that code. I Hope that's can solve your probelms. Thank you :)
Using firefox right click on the cart and open inspector. Find the css used on the right panel. Then, in modify theme, add custom css like:
.woocommerce-active .site-header .site-header-cart {
display: none !important;
}
(In the above code «.woocommerce-active .site-header .site-header-cart» was in the right panel of "inspector". While in modify mode you can instantly see the result, so make some tries if CSS name is not the correct one.)
What worked for me was finding the class associated with cart using the inspect tool in Chrome (any browser should provide the same feature). Customize the theme appearance and add custom CSS.
.cart-button {
display: none !important;
}
Watch the video showing the steps (there's no audio) at https://www.loom.com/share/9f9d1a8d3fb346e0b954c8c26f06a926
To remove shopping cart from WooCommerce plugin in Wordpress, select the Disable option in Menu cart:Display
Go to Appearance>Customize>WooCommerce>General>Menu cart

wordpress : how to add categories and tags on pages?

I have generated pages using a custom template by creating a php file in my theme directory
something like :
<?php
*
* Template Name: Contact Page
*/
?>
<html ..... </html>
and then adding a new page on the dashboard selecting this new template
How can i now associate tags and categories to each pages ?
Is creating posts instead of pages the only solution?
Even better is to add to functions.php in your theme folder:
function myplugin_settings() {
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action( 'init', 'myplugin_settings' );
Tried using the accepted answer but for some reason it only shows the Post types and none of the Pages shows in the category page. E.g. /category/entertainment/
To fix that, I have to do this:
// add tag and category support to pages
function tags_categories_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
// ensure all tags and categories are included in queries
function tags_categories_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any');
}
// tag and category hooks
add_action('init', 'tags_categories_support_all');
add_action('pre_get_posts', 'tags_categories_support_query');
Try this:
add_action( 'init', 'wpse34528_add_page_cats' );
function wpse34528_add_page_cats(){
register_taxonomy_for_object_type('post_tag', 'page');
register_taxonomy_for_object_type('category', 'page');
}
Not at all helpful to say 'download plugin' for beginners who are most likely not going to have downloaded wordpress and are therefore not able to install said plugin. Here is some short code for those like me that have been scouring the web for something that actually works on regular pages with regular accounts - ie you're not a developer.
First, make sure you have your pages in your menu set up properly.
YOU DO NOT NEED TO MAKE YOUR PAGES 'Categories' or 'Tags'!
This wouldn't give you actual pages to then go and edit, so if you are wanting to add sliders, text, an intro, or anything for that matter, you wouldn't be able to.
Then go to WP Admin > Pages
Select a page to edit and go to the text editor instead of visual editor (far right hand side tab)
Then past the following short code:
[display-posts category="hair,makeup,reviews,beauty" posts_per_page="10" include_date="true" text-decoration: none date_format="F j, Y" order="DESC" include_excerpt="true" wrapper="div" image_size="large"]
<
(The shortcode collects all the posts that you have assigned certain categories in your blog posts i.e. mine was hair and beauty. So obviously change yours to ones that are appropriate. It then allocates how many posts (mine was 10), the date (in descending order,) with a large image and an excerpt of the post)
this plugin sorted me out :
http://wordpress.org/extend/plugins/add-tags-and-category-to-page/
with the standard instructions :
Upload the plugin files to the /wp-content/plugins/ directory
Activate the plugin through the 'Plugins' menu in WordPress
Use the setting page of the plugin from Settings > Add Tags And Category For Page.

Resources