Remove Variations from "Cart Form" - php

I am trying to move add to cart button under button(cart form) under the product image and leave variations where they are.
But with below hook variations are also going under the product image
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
Any way to make only button move under the image and not variations form.
Here is the screenshot:
Thank You
Tried following solution but no Luck
Try 1:
remove_action( 'woocommerce_single_variation', 'remove_variation', 10 );
function remove_variation(){
woocommerce_single_variation();
}
Try 2:
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );

Default Actions:
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
Remove Default Actions:
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 10 );
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
Add Custom Action:
add_action( 'woocommerce_single_variation', 'new_custom_action', 5 );
function new_custom_action() {
echo 'TEST';
}

If you look at the default variable template in woocommerce/templates/single-product/add-to-cart/variable.php you can see that for variable products, it combines both the variations drop-downs and the add to cart button together in the 'woocommerce_single_variation' hook:
/**
* woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
* #since 2.4.0
* #hooked woocommerce_single_variation - 10 Empty div for variation data.
* #hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
You can either customise this file within your theme to change this behaviour, or remove the woocommerce_single_variation function from this hook and add it somewhere else.

Related

How i can change default add to cart button in WooCommerce?

This is how it all looks
I want to add a new "add_to_cart" button template for the outer product card without affecting the inner one. but when I add, the old one remains. What's wrong with my code?
it is my code in functions.php
function loop_custom_variable_products() {
global $product;
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 30 ); // Remove price
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 30); // remove add to cart
remove_action( 'woocommerce_after_shop_loop_item', 'loop_variations_custom_buttons_and_prices', 30 ); // Add prices with custom buttons
}
add_action( 'init', 'loop_custom_variable_products' );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_variable_add_to_cart1', 30 );
//add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_variable_add_to_cart1', 30);
function woocommerce_variable_add_to_cart1(){
//... some code for new add to card style
}

Why is WooCommerce function not overriding the default function in child theme

I have a child theme that I am trying to override a WooCommerce function.
WooCommerce file in plugin location: woocommerce/includes/wc-template-hooks.php. I created a new file in the same hierarchy in my child theme and it's located here: my-child-theme/woocommerce/includes/wc-template-hooks.php
My edited section is I commented out the product title in child theme:
/**
* Product Summary Box.
*
* #see woocommerce_template_single_title()
* #see woocommerce_template_single_rating()
* #see woocommerce_template_single_price()
* #see woocommerce_template_single_excerpt()
* #see woocommerce_template_single_meta()
* #see woocommerce_template_single_sharing()
*/
//add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 ); //commented
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
However, when I goto my product page, I still see the title.
Any idea what I am doing wrong?
You need to remove action woocommerce_single_product_summary to this work properly.
add_action( 'woocommerce_before_single_product', 'remove_woocommerce_single_product_summary', 10 );
function remove_woocommerce_single_product_summary() {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
}
Just add this to your functions.php and will do the magic.
You also can try to add remove_action() out of the add_action(). Just like this...
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 15 );
...directly to functions.php
Play with it.
TIPS & TRICKS
If you want to change your HTML in the title or do anything you want, here is example:
add_action( 'woocommerce_before_single_product', 'remove_woocommerce_single_product_summary', 10 );
function remove_woocommerce_single_product_summary() {
// First, we remove it
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
// Second, we add new title
add_action( 'woocommerce_single_product_summary', 'woocommerce_my_new_title', 1 );
}
function woocommerce_my_new_title(){
echo '<h1 class="some-my-custom-classes">' . the_title() . '</h1>';
}
If your active theme does not support Woocommerce and you want to add
a Woocommerce template to your active theme, you must register
WooCommerce, or give Woocommerce features.
Check out these links for more details:
https://github.com/woocommerce/woocommerce/wiki/Declaring-WooCommerce-support-in-themes
https://docs.woocommerce.com/document/template-structure/
One important thing:
If you change the template folder within the Woocommerce plugin, there is a good chance that you will lose your settings after the plugin update. That is why it is better to work in an active theme.
function my_custom_action() {
echo '<p>Hello here</p>';
};
add_action( 'woocommerce_single_product_summary', 'my_custom_action', 15 );

Time based Enable/Disable WooCommerce add to cart functionality

I'm searching for a method to make this:
From Monday - Sunday from 5pm to 2pm the add to cart is enabled, before or after this time, the add to cart button needs to be disabled.
On Tuesday the complete day, the Shop is closed, so the add to cart is disabled.
I found this snippet to disable the add to cart but without the time and day specification:
/**
* #snippet WooCommerce Holiday/Pause Mode
* #how-to Watch tutorial # https://businessbloomer.com/?p=19055
* #sourcecode https://businessbloomer.com/?p=20862
* #author Rodolfo Melogli
* #testedwith WooCommerce 2.6.4
*/
// Trigger Holiday Mode
add_action ('init', 'bbloomer_woocommerce_holiday_mode');
// Disable Cart, Checkout, Add Cart
function bbloomer_woocommerce_holiday_mode() {
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_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
add_action( 'woocommerce_before_main_content', 'bbloomer_wc_shop_disabled', 5 );
add_action( 'woocommerce_before_cart', 'bbloomer_wc_shop_disabled', 5 );
add_action( 'woocommerce_before_checkout_form', 'bbloomer_wc_shop_disabled', 5 );
}
// Show Holiday Notice
function bbloomer_wc_shop_disabled() {
wc_print_notice( 'Our Online Shop is Closed Today :)', 'error');
}
My English is not good, but I hope you can help me.
Here's something to get you started, this piece of code will check if today is Tuesday and if it is then the add to cart functionality will be disabled.
function bbloomer_woocommerce_holiday_mode() {
$disable_cart = my_wc_disable_add_to_cart();
if( $disable_cart ) {
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_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
add_action( 'woocommerce_before_main_content', 'bbloomer_wc_shop_disabled', 5 );
add_action( 'woocommerce_before_cart', 'bbloomer_wc_shop_disabled', 5 );
add_action( 'woocommerce_before_checkout_form', 'bbloomer_wc_shop_disabled', 5 );
}
}
function my_wc_disable_add_to_cart() {
// Tuesday is day number 2 of the week
$day_of_week = date("w", current_time());
if( $day_of_week === 2 )
return true;
return false;
}
It will be a similar process adding the other time criteria for enabling/disabling the cart.
i'm trying to write my own snippet and this is what I achieved so far:
add_action( 'wp_head', 'disable_checkout_sunday' );
function disable_checkout_sunday(){
if (date(D) == "Sun"){
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');
remove__action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form');
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form');
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review');
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment');
}
}

WooCommerce Hide Add To Cart Button on Loop & Product Page

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';
}

Edit WooCommerce Shop page, Title before thumbnail

I've bitten off more than I can chew and need some help with WooCommerce.
I'm trying to edit the shop front page (i've managed to do the product single pages fine) but can't find the out put for the hooks anywhere.
Basically, all i'm trying to do is make the Title of the product appear before the thumbnail and add a"view" button after the thumbnail.
I'm literally pulling my hair out so if anyone could help i'd be extremely grateful!
Add below on function.php
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 90 );
Adding above code will duplicate you thumbnail, then add below CSS will do trick.
.product-images { display: none; }
You should to see in plugin/woocommerce/woocommerce-hook.php
Form Line 100 - 107
/**
* Before Single Products Summary Div
*
* #see woocommerce_show_product_images()
* #see woocommerce_show_product_thumbnails()
*/
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
/**
Form Line 120 - 132
/**
* Product Summary Box
*
* #see woocommerce_template_single_title()
* #see woocommerce_template_single_price()
* #see woocommerce_template_single_excerpt()
* #see woocommerce_template_single_meta()
* #see woocommerce_template_single_sharing()
*/
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
//add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
/**
Change order of add_action
Change value of the second arg
Good luck!

Categories