remove variation in woocommerce - wordpress

I am having 3 attributes in variations: Color, size, and ship from. I am using only 1 warehouse to ship products now. I have removed other warehouse locations from attributes. but product variations are still there. I want to remove all variations that are having blank values for the "ship from" part. Kindly help me with any SQL command or any other way to remove those variations with the "ship from " part blank.

Try this
Functions.php
add_action( 'woocommerce_single_product_summary', 'removing_variable_add_to_cart_template', 3 );
function removing_variable_add_to_cart_template(){
global $product;
// Only for variable products
if( $product->is_type( 'variable' ) ){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}

Related

Woocommerce: Add to cart on category page not adding when filter is applied

I put this code on my website to be able to add products directly from the product list instead of the single product page and everything works well when I add them from the category page:
add_action( 'woocommerce_before_shop_loop', 'handsome_bearded_guy_select_variations' );
function handsome_bearded_guy_select_variations() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 30 );
}
Except when I use filters, apparently, is not getting the variable product information once I have a filter active, and there is a message saying that I need to add the product from the single product page. Can someone help me figure out how to make it work with filters?
Demo: https://802cabinetry.com/style/stowe-light-gray/
enter image description here
Thanks.

Hide price for specific category and only specific user role to purchase from that category in WooCommerce

Hi can anyone lead me in the right direction. This is what I am trying to achieve with my WooCommerce store. I have a store that has categories available to the general public but one category is a specialized category and requires approval to purchase so I want to create a specific user role for this category.
Ive been able to achieve hidden prices on one category but cant seem to work out how to restrict the purchase of that category and reveal prices to a specific user role.
So for example
The parent category Sample category and all its sub categories is to have a hidden price unless a user role “sample category Customer” is logged in. Instead of a price it will have the text “register for price”
Only the user role sample category Customer can purchase items from the sample category and its sub categories. Any other user role will be prohibited from purchasing items from the category but the items will still be visible to them with a hidden price.
The sample category user can purchase from anywhere
All other categories to have visible prices for all user roles. All categories including the Sample category (which will have hidden price )to be visible for everyone
thank you for any help
Vanessa
Below, I have modified some code I've written previously for wholesale customers. The code removes the price and 'Add to Cart' button, and prevents those products being purchased at all.
add_action( 'template_redirect', 'hide_price_and_add_cart' );
// The first hook that is safe to get post id is template_redirect
function hide_price_and_add_cart() {
$postID = get_queried_object_id();
if ( ( is_product( $postID ) && has_term( 'sample_category', 'product_cat' ) ) ||
// if single product pages in the category "sample_category"
( is_product_category( 'sample_category' ) )
// or, if product category pages "sample_category"
) {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
if ( ! in_array( 'sample_category_customer', (array) $user->roles ) ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
// remove 'Add to Cart' from product category page
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
// remove 'Add to Cart' from single product page
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
// remove price from product category page
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// remove price from single product page
add_action( 'woocommerce_single_product_summary', 'print_login_to_access', 31 );
// Print 'Register for price' on single product page
add_action( 'woocommerce_after_shop_loop_item', 'print_login_to_access', 11 );
// Print 'Register for price' on product category page
add_filter( 'woocommerce_is_purchasable', '__return_false');
// Finally, let's just make sure the product cannot be purchased...
}
} else {
// If user is not logged in, hide everything as well
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_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'print_login_to_access', 31 );
add_action( 'woocommerce_after_shop_loop_item', 'print_login_to_access', 11 );
add_filter( 'woocommerce_is_purchasable', '__return_false');
}
}
}
function print_login_to_access() {
echo '<p>Register for price</p>';
}
Note - this code only works for products listed in the parent category "Sample Category". It will work for products in sub categories, if they are also listed in the parent cat. If you don't want them to be listed in the parent cat as well - only the sub cats - you'll need some code to recursively drill down and identify the parent.

Move "Add to Cart" form below product description

I want to move only add to cart form below products description. To explain better:
Found this function, but it moves this at top of product under description. So some part of function is not right. Can someone to help me?
add_action( 'woocommerce_single_product_summary',
'customizing_variable_products', 1 );
function customizing_variable_products() {
global $product;
if( ! $product->is_type( 'variable' ) ) return;
remove_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_add_to_cart', 15 );
}
You have to copy / paste all the woocommerce templates into your current template folder.
This way, the woocommerce theming isn't gonna take it's own templating but will take the one you pasted instead.
Then, you'll just have to find, where, in the template files where is printed the options, and where is printed the add to cart button. You'll be then able to switch the code sa that it makes what you need.
here is the doc about how overriding templates files.

Hiding prices in WooCommerce for a set of products

In our Woocommerce products, we have two types of products.
Products imported through script from a external XML url file.
Products added as usual through woo admin interface.
We have added a meta field to identify these imported products.
What is the best method to hide prices ONLY for these imported products?
I have tried by removing some woocommerce actions, but its affects all woo products.
I have tried by removing some woocommerce actions, but its affects all woo products.
Then you need conditional logic. This should get rid of the price display in the loop.
EDIT As pointed out in the comments, once you remove the action it is permanently removed for all ensuing products. So in light of that I have added an else statement that resolves this issue.
function so_32584641_remove_price_from_loop(){
global $product;
if( 'mycbgenie' == get_post_meta( $product->id, '_mycbgenie_managed_by', true ) ){
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price' );
} else {
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price' );
}
}
add_action( 'woocommerce_before_shop_loop_item', 'so_32584641_remove_price_from_loop' );
and this should remove it from the single product page:
function so_32584641_remove_price_from_single(){
global $product;
$your_meta = get_post_meta( $product->id, '_your_meta_key', true );
if( 'mycbgenie' == $your_meta ){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' );
}
}
add_action( 'woocommerce_before_single_product', 'so_32584641_remove_price_from_single' );

How to deacivate related products on wordpress?

I am working on wordpress,the plugins are :woocommerce,datafeedr api,and datefeedr product sets,I added some products from datafeedr also in woocommerce,now I want to deactivate the related product temporarily,I don t went to remove them.
remove_action(
'woocommerce_after_single_product_summary',
'woocommerce_output_related_products',
20
);
If that didn't work, remove it and use this in functions.php:
add_filter(
'woocommerce_related_products_args',
'_remove_related_products',
10
);
function _remove_related_products( $args ) {
return array();
}
I hope this one work, if didn't, you change 10 to 20, 30 or ... until it works, I hope.

Resources