I am using this function to add a variation and quantity fields to my archive pages-
add_action( 'woocommerce_before_shop_loop', 'my_select_variations' );
function my_select_variations() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
I am then removing the price range from all pages using this-
add_filter( 'woocommerce_variable_sale_price_html', 'my_remove_variation_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'my_remove_variation_price', 10, 2 );
function my_remove_variation_price( $price ) {
$price = '';
return $price;
}
This works well, however I am not satisfied with the order of the files for my variation products. How can I change the order of the variation price so that it is above the drop down box, as illustrated here? Is there a simple way to do this through the I better off using jQuery to relocate the price?
EDIT: Using the below I have moved the price on single product pages, but not on archive pages yet.
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_before_variations_form', 'woocommerce_single_variation', 10 );
Related
Im trying to hide the add to cart button in woocommerce for all products except a varibale product i have. I have tried the following which leaves the variable select options (which is what i want) but it hides the add to cart button (which i don't want).
add_filter( 'woocommerce_is_purchasable', '__return_false' );
add_action( 'woocommerce_single_product_summary', 'hide_add_to_cart_button_variable_product', 1, 0 );
function hide_add_to_cart_button_variable_product() {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20);
}
Is there a way to do this?
All my products are simple products except for this single variable products, so maybe there is a function to hide the cart button for all simples except variables?
add_action('woocommerce_single_product_summary', 'wp66176371_remove_product_description_add_cart_button', 1 );
function wp66176371_remove_product_description_add_cart_button() {
global $product;
if ( !empty($product) && $product->is_type( 'simple' ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
I think you can just edit the simple.php template file in the add-to-cart directory so it wouldn't show the button for simple products.
In content-product.php, products from the current category page have a "add to cart"-button if the item has a price.
I want to remove this button, BUT only on the items that returns true on the if statement around it.
I tried:
$showBuyButtonNo = get_field('show_buy_button');
if ($showBuyButtonNo) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
BUT this does it to all items.
You can update default WooCommerce content-product.php as below:
add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );
function remove_add_to_cart_buttons() {
// replace a_category and another_category with the slugs of the categories you'd like to have the button removed from
if( is_product_category( array( 'a_category', 'another_category'))) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}
}
Reference: https://www.wpblog.com/add-to-cart-button-in-woocommerce-store/
Reference: https://gist.github.com/rynaldos/560c621714b9680433cddf18e6a50305
In my WooCommerce shop I want to hide the prices until the customer has logged in. I've got the following code working that does exactly that:
add_action('init','hide_price');
function hide_price(){
if(!is_user_logged_in()){
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_single_product_summary','woocommerce_template_single_price',10);
remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_price',10);
add_action('woocommerce_single_product_summary','print_login_to_see',31);
add_action('woocommerce_after_shop_loop_item','print_login_to_see',11);
}
}
function print_login_to_see(){
echo '' . __('Login to see prices','theme_name') . '';
}
However this also removes the variation drop down and I would like to keep that.
Is there any direct way to keep the variation drop down menu but still hide the prices until the customer has logged in?
Thanks
Updated:
You will need to separate shop and archives pages from single product pages. In single product pages you will target variable products to add and remove the specific hooked functions.
Last thing, in your function print_login_to_see(), woocommerce_get_page_id() is obsolete and it's replaced by wc_get_page_id() …
So your code will look to this:
// For product archives pages
add_action( 'init', 'hide_product_archives_prices' );
function hide_product_archives_prices(){
if( is_user_logged_in() ) return;
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10) ;
add_action ( 'woocommerce_after_shop_loop_item', 'print_login_to_see', 10 );
}
//
add_action( 'woocommerce_single_product_summary', 'hide_single_product_prices', 1 );
function hide_single_product_prices(){
if( is_user_logged_in() ) return;
global $product;
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
if( ! $product->is_type('variable') ){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary','print_login_to_see', 30 );
} else {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10);
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
add_action( 'woocommerce_single_variation', 'print_login_to_see', 20 );
}
}
// Display a my account link
function print_login_to_see(){
echo '' . __('Login to see prices','theme_name') . '';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested on WooCommerce 3+ and works.
I want something on woocommerce.
That when I set zero price on a product, it shall not show it (the value) , just set it out of stock.
and hide add to cart button in product page.
It can be done by implementing the Catalogue Mode
/****** REMOVE THE ADD TO CART BUTTON ****/
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 PRICE FROM ALL PLACES *******/
add_filter( 'woocommerce_variable_sale_price_html', 'theme_remove_prices', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'theme_remove_prices', 10, 2 );
add_filter( 'woocommerce_get_price_html', 'theme_remove_prices', 10, 2 );
function theme_remove_prices( $price, $product ) {
$price = '';
return $price;
}
Hope it will help you
I'm working on a woocommerce theme and I'm required to hide the add to cart button for products that have 0 as price, as these products may only be inquired and not added to cart. I have successfully hidden the 'add to cart' button on the product page however, I am having a hard time doing so on the shop page/category page.
Below is my code for filtering the add to cart as well as changing the default 'Free!' message.
add_filter( 'woocommerce_variable_free_price_html', 'hide_free_price_notice' );
add_filter( 'woocommerce_free_price_html', 'hide_free_price_notice' );
add_filter( 'woocommerce_variation_free_price_html', 'hide_free_price_notice' );
/**
* Changes woocommerce default 'Free!' to return message
*/
function hide_free_price_notice( $price ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
return 'Please inquire for pricing';
}
I have also tried filtering all add to cart buttons on loop, however this did not work either.
add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );
function remove_add_to_cart_buttons() {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
}
Any suggestions? I'm looking to see if I can hide it with CSS...
This is what I use to change the 'Free!' message to 'POA' and also hide the cart.
Note: There seems to be an issue with this on WooCommerce version V2.1?
* Swop the 'Free!' price notice and hide the cart with 'POA' in WooCommerce
*/
add_filter( 'woocommerce_variable_free_price_html', 'hide_free_price_notice' );
add_filter( 'woocommerce_free_price_html', 'hide_free_price_notice' );
add_filter( 'woocommerce_variation_free_price_html', 'hide_free_price_notice' );
function hide_free_price_notice( $price ) {
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 );
return 'POA';
}