Woocommerce product price duplicating - wordpress

I want to add two prices on single product, first simple price was showing but when clicking on cariation size, price was duplicating, simple and variation both price showing, I want to show one price at a time.

Fix 2x price
GoTo: www.YOURDOMAIN/wp-admin/admin.php?page=wc-settings&tab=tax
then remove {price_excluding_tax} from "Price display suffix" input field

You Can try with jquery onchange function and get above product price and show at bottom

You can try to use this code. Hope it will work.
add_action( 'init', 'wp1232_remove_price_for_variations', 99 );
function wp1232_remove_price_for_variations() {
global $product;
if ( 'variable' == $product->get_type() ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
}
}

Related

Woocommerce how to remove Variation select list and show it in a custom hook

In a Woocommerce Product Page I need to remove the Variation Select Lists from the default placement and show them y my custom hook:
"flatsome_custom_single_product_3"
How can I do this?
I tried with this, but not working.
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'flatsome_custom_single_product_3', 'woocommerce_single_variation', 10 );
Take a look at this capture to see what I mean:
You could first remove the default variation and then add your own using the following hook:
remove_action('woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30);
add_action('woocommerce_variable_add_to_cart', 'custom_variable_div', 15);
add_action('woocommerce_variable_add_to_cart', 'woocommerce_single_variation_add_to_cart_button', 20);
function custom_variable_div(){
# Make up your own stuff
}
I've tested it and it works seamlessly fine!

Conditionally Hiding Pricing; Need to Make Visible from Tag/Custom Taxonomy

Hide product pricing & add to cart button unless logged in
Sale items be visible, logged in or not, if visited from some kind of tag, category, or other taxonomy so that nobody sees the sales unless they are directed to them explicitly.
Example: All product prices are hidden, except on URLs with the tag "waffles-sale". This is a simple example but I think that explains what I'm after with 2.
I've accomplished 1. with a plugin, and more recently a short code; this works great:
add_action( 'init', 'bbloomer_hide_price_add_cart_not_logged_in' );
function bbloomer_hide_price_add_cart_not_logged_in() {
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', 'bbloomer_print_login_to_see', 31 );
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
}
}
function bbloomer_print_login_to_see() {
echo '' . __('Please login for pricing.', 'theme_name') . '';
}
But this leaves me with two, which is making things visible conditionally. I am sorry if this is vague. I've scoured the web for answers but I'm coming up short. I feel like my vocabulary is holding me back; I don't know the words for the hooks or phrases that I'm describing. I would love to stop reinventing the wheel (I'm having to clone products/product categories to make only them visible from temporarily published pages for sales).
Can anyone point me in the right direction? Is controlling product visibility in this way possible? I would greatly appreciate anyone's more experienced two cents or solution to this. Thank you.
You could try this (haven't tested), wrote it on rush, but it should help you in achieving what you need.
You need to define the query string then add/remove actions depending on what you need based on that query string.
Use the get_query_string:
// register query var
add_action('init','register_query_string');
function register_query_string() {
global $wp;
$wp->add_query_var('my_query_string_name');
}
//check if it's in the url
if ( get_query_var('my_query_string_name') ) {
// remove/add actions for the query string
elseif ( !user_not_logged_in()){
//something when not logged in
}
}
in case you need to check for query string and logged in, you can do something like
if ( !get_query_var('my_query_string_name') && ( !user_not_logged_in()){
// insert magic here
}
Code goes into functions.php from your child theme (or a plugin).

How to hide the variable price from single product only in woocomerce?

I want to hide the variable price from the product page only, not from all thr other pages like the shop page. And i dont want the price for each variation to be hidden. Only the range variable price. I have searched all the web but all the solution hide the price from the shop also or hide the price for each variation also.
In your content-single-product.php woocommerce template, you can hide the range variable price only in product page by removing the single price function from the single product summary action :
global $product;
if ( $product->is_type( 'variable' ) ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' );
}

Add amount option for each variation

I am building a website that sells products with different variation. I created some variations to the products. However, the variations on the single product show up in a select box.
I want the customer to be able to choose an amount they want for each variation on the same page.
For example:
Chocolate 2x (customer chooses 2 Chocolate variations)
Vanille 3x
I want the customer to be able to buy those 5 flavours in 1 go and that they can select the amount for each variation of the product.
How can we reach this?
You should use Grouped Product.
It will look something like this on the frontend.
if you insist on using the variable product and treat it like it's a group, we can do that too.
First we have to remove the hook for the add to cart form of the variable product like so:
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
then we have to change it to use the add to cart form of the grouped variable like so:
add_action( 'woocommerce_variable_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
in doing so, you'll end up something like this on the front end:
take note of the dashes after the quantity input. It's in format Title - Variation
So this must be it. Then when you're about to do an add to cart it shows like this:
It says "Please choose product options…". Why so? This is because the product is of type variable, and we are expected to choose on option. Remember select box.
However, we can fixed it like this:
add_filter( 'woocommerce_add_to_cart_handler', 'woocommerce_add_to_cart_handler', 10, 2 );
function woocommerce_add_to_cart_handler( $product_type, $product ) {
// if ( in_array( $product->get_id(), array( 100, 99, 504 ) ) ) {
$product_type = 'grouped';
// }
return $product_type;
}
We'll change the product type of the form handler. This way, we're using the grouped form handler and not the variable. Just be careful to put a conditional statements like if to only apply to specific products. Or else you'll end up confused between grouped products and variable products if you know what I mean. I've also recklessly did an add_action( 'woocommerce_variable_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 ); without conditional statement, I suggest you do.
But once everything is in place, it will look something like this:

Hide WooCommerce Add To Cart button when price is zero

I need to hide my add to cart button on the condition where the price = 0.00. If the price is greater than 0.00 i would like the button to reappear.
However i also use the WooTheme Wish List extension and i need the add to wish list button to remain. I would also like to change the text from Free to "Subscription Product" when the value is 0.00.
This is only needed on the single product page as we do not show the add to cart anywhere else.
Currently if the price is set to 0.00 i get the text at the top of the single product page saying "free" and the add to cart button remains as does the add to wish list button. If i remove the price all together the buttons also disappear hence why i need to "hide" the button to retain the wish list one.
I have tried the following Code inserted into my functions.php file
<?php
/*
* 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';
}
?>
However, although it did work in that it changed the "Free" text to "POA" and also hid the "Add to Cart button" the "Add to Wishlist" button also disappeared.
If i changed the value to 0.01 everything appeared again so it nearly there... i just need the Wish List button to stay.
Any help or pointers would be greatly appreciated. Many Thanks...
Just for info, the reason i need to do this is because we run a subscription service, so products that are included in a subscription service do not need a price but do need to be shown so they can be added to a wish list. However sometimes we sell the products off so when they have a value i need the button to reappear so they can be added to the cart.
Simply having zero doesn't work because believe it or not people think they are free and try to add them to the cart to purchase !
Please add below code in your active theme functions.php and check it.
function wpcustom_is_purchasable( $purchasable, $product ){
if( $product->get_price() == 0 )
$purchasable = false;
return $purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'wpcustom_is_purchasable', 10, 2 );

Resources