Woocommerce - Catalogue Add to Cart button - change default quantity for specific category - wordpress

On the woocommerce shop catalogue page is it possible to have the 'add to cart' button default to six rather than one, but only for a specific category? Selling wine and want it to add 6 bottles at a time, but also selling other items that will be sold individually.

Add this code to functions.php in your theme. Keep in mind that if you update your theme, this edit might be lost. So either save it somewhere to add it again or create a child theme and add it there.
add_filter("woocommerce_quantity_input_args", function($args, $product){
if(!is_cart() && has_term("wine-bottles", "product_cat", $product->get_id())) {
$args['input_value'] = 6;
}
return $args;
}, 10, 2);
Replace "wine-bottles" with the actual name, slug or ID of your category.
This will make the default quantity value be 6 for all products in the specified category on all pages where they're displayed.

Related

How to disable Default Post Category in WordPress?

I'm creating a new post without selecting category but whenever new post is created at that time it automatically selects category. I want to disable auto select category.
Can anyone help me?
The best way of removing default category is to change a parameter is to change the parameter 'default_category' in your 'wp_options' table.
Set the parameter 'default_category' to 0. Note that it won't change the category displayed in your dashboard in the Writing settings, but it will prevent Wordpress to set a default term to your post.
Wordpress doesn't require a term or category to be set by default. It's just not true ;)
Every single post created in Wordpress will be assigned to a category by default. Even if you don't create categories, Posts will be assigned to a default category called "Uncategorized". This is how the Wordpress system works.
First of all, can you explain to us why you don't want to assign categories?
is this because you don't want the category slug added to the post URL? If this is the reason, there are so few ways to achieve this.
This plugin removes the CATEGORY slug from the post URL.
https://wordpress.org/plugins/remove-category-url/
Few other references to removing Category slug from URL without plugins:
https://jonnyjordan.com/blog/how-to-remove-category-from-your-urls-in-wordpress/
Remove category & tag base from WordPress url - without a plugin
Wordpress post will have 1 CATEGORY. This is how Wordpress works. Maybe if you want to remove the default category but if you want to select a category manually then we can achieve that with some custom coding. But you cannot have a WordPress post without assigning a category to it.
The below code will remove the default category when another category is set to a post. Make sure you have set the default category as Uncategorized.
//remove default category (uncategorized) when another category has been set
function remove_default_category($ID, $post) {
//get all categories for the post
$categories = wp_get_object_terms($ID, 'category');
//if there is more than one category set, check to see if one of them is the default
if (count($categories) > 1) {
foreach ($categories as $key => $category) {
//if category is the default, then remove it
if ($category->name == "Uncategorized") {
wp_remove_object_terms($ID, 'uncategorized', 'category');
}
}
}
}
//hook in to the publsh_post action to run when a post is published
add_action('publish_post', 'remove_default_category', 10, 2);
Do let me know if this helps.

Woocommerce: How to remove category on ALL pages

I am using Woocommerce in combination with Booked to make paid reservations for our Escape Rooms. The products that i sell are just the different booking options such as: Room A | 4 Persons | €50
When making a reservation (buying the woocommerce product) it automatically shows "Category: No category". I don't want that because when people click the "no category" they get to see the categorypage that i don't use. The pages "shop" and "all products" are also not used for my purpose.
How can i remove the categories from the following pages?: Cart, Checkout
Picture of the Cart
Picture of the Checkout
Is it possible to add some lines in the Functions.php of the theme which makes the categories disappear? I already added some 3 lines that hide three columns (download-remaining, download-product and download-expires) and it works perfect for my purpose!
Here is the code i have used (copied from another article ;))
add_action( 'woocommerce_account_downloads_columns',
'custom_downloads_columns', 10, 1 ); // Orders and account
add_action( 'woocommerce_email_downloads_columns',
'custom_downloads_columns', 10, 1 ); // Email notifications
function custom_downloads_columns( $columns ){
// Removing "Download expires" column
if(isset($columns['download-expires']))
unset($columns['download-expires']);
// Removing "Download remaining" column
if(isset($columns['download-remaining']))
unset($columns['download-remaining']);
if(isset($columns['download-product']))
unset($columns['download-product']);
return $columns;
}
This is the website: https://escape-outdoor.nl

woocommerce product attributes dropdown not appear

i can't select product color or size before add product to cart .
all attributes showing like text not selection
i need to show product attributes dropdown list (options)
i try :
// Remove additional information tab
add_filter( 'woocommerce_product_tabs', 'remove_additional_information_tab', 100, 1 );
function remove_additional_information_tab( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
enter image description here
Once you’ve created attributes you’ll need to use those to create variations on your product. I assume what you’re saying is that you click on an attribute and it then takes you to a page showing you any product that is using that attribute.
once your attributes are added to the product follow the rest of this doc to get variations created. Then you’ll have drop down options for those variations on your product.

Show children for subcategory archives in Woocommerce Product Category widget

I'm building a shop with Woocommerce and using WooCommerce Product Category widget. I have set many product categories with subcategories. One of these categories is "Posters" and has several subcategories, like "Star signs", "Travel", "Nature"…
By default Woocommerce only shows the parent categories which is good. If I click a category "posters", I'm redirected to "posters" category archive page and the widget displays all "Posters" children subcategories and it's perfect.
Now, if I click on one of these "Posters" children subcategories, I'm redirected to the respective archive page, but my navigation doesn't show all other "Posters" children subcategories anymore.
The question:
How do I get all parent category and "sibling" subcategories while browsing a subcategory?
Random example of the standard navigation when collapsed:
Phone Cases
Mugs
Pillows
Posters
Shirts
Stickers
Example of navigation when "Posters" has been clicked:
Phone Cases
Mugs
Pillows
Posters
--Star Signs
--Travel
--Nature
--Abstract
--Typography
Shirts
Stickers
When a subcategory is clicked, e.g. "Nature", the navigation returns to look like the first example given, all collapsed. But I want it to stay expanded like in the second example.
Bellow in the screenshot are my settings for Woocommerce Product Category widget:
Any help will be appreciated.
Your settings are correct. The code below is targeting archives category pages only and it will display now all children subcategories in the Woocommerce Product Category widget, for the current subcategory:
add_filter('woocommerce_product_categories_widget_args', 'widget_product_categories_list_args', 10, 1);
function widget_product_categories_list_args( $list_args ) {
global $wp_query;
// Only for category archives pages
if ( is_tax( $list_args['taxonomy'] ) ):
// Get current category
$current_cat = $wp_query->queried_object;
// Get all Included category terms IDs in the widget
$included_ids = explode( ',', $list_args['include'] );
// Get All Childrens Ids from parent term or from current term
if($current_cat->parent != 0 )
$childrens = get_term_children( $current_cat->parent, $list_args['taxonomy'] );
else
$childrens = get_term_children( $current_cat->term_id, $list_args['taxonomy'] );
// Loop through Children term Ids and add them to existing included ones
foreach( $childrens as $child )
$included_ids[] = $child;
// Replace included product category term IDs in the $args array
$list_args['include'] = $included_ids;
endif;
return $list_args;
}
Code goes in function.php file of the active child theme (or active theme).
Tested and works.

Woocommerce is it possible to disable quantity field on cart page, for some product?

Basically, I finished building custom plugin for my client.
the only thing after products added to cart, before the checkout.
user able to change the quantity of the products, is it possible to display the selected quantity, but disabled the options to read only so client will able to see the quantity in cart page that he selected but can't change it?
and to apply this only to products that I used with my plugin either product ids or better category id because all the products there.
other product display and able to change quantity regular
by the way its regular products not virtual and not Sold Individually i need to find a way to limit clients to change quantity for some products only in cart page!, and not in product page.
I really appreciate any help.
As mentioned in the comment, you can use the woocommerce_cart_item_quantity filter for that. So that might look something like this:
function 668763_change_quantity_input( $product_quantity, $cart_item_key, $cart_item ) {
$product_id = $cart_item['product_id'];
// whatever logic you want to determine whether or not to alter the input
if ( $your_condition ) {
return '<h3>' . $item['quantity'] . '</h3>';
}
return $product_quantity;
}
add_filter( 'woocommerce_cart_item_quantity', '668763_change_quantity_input', 10, 3);
This would be just a simple example to replace the input with a h3 element containing the quantity. It can easily be adjust to alter the quantity input element to your liking.

Resources