Move "Add to Cart" form below product description - wordpress

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.

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.

Show custom text block on product page only if a product is out of stock with backorder enabled

i have a wordpress site with woocommerce and flatsome theme. The theme give the possibility to add easily a custom html text before or after the add to cart button.
I would like that the html text show up only for out of stock with backorder enabled products, for single and variables products.
the theme have this code
// Add HTML after Add to Cart button
function flatsome_after_add_to_cart_html(){
echo do_shortcode(get_theme_mod('html_after_add_to_cart'));
}
add_action( 'woocommerce_single_product_summary', 'flatsome_after_add_to_cart_html', 30);
any help is appreciated
You can likely do that with just an additional couple of checks in your function. Before echoing the content - check the $product like this:
function flatsome_after_add_to_cart_html(){
global $product;
if( ! $product->is_in_stock() && $product->backorders_allowed() ){
echo do_shortcode(get_theme_mod('html_after_add_to_cart'));
}
}
add_action( 'woocommerce_single_product_summary', 'flatsome_after_add_to_cart_html', 30);

remove variation in woocommerce

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

How to change position of Add to Cart Button on Single Product

I would like to change position of Add to Cart Button on Single Product. I've tried to used code below:
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', 9);
Unfortunately it doesn't work with My Theme. The result is that Add to Cart Button is double. The screenshot below:
Add cart button displaying twice with My Theme
When I change the Theme to different one (Twenty Nineteen), every thing seems to be okey. The screenshot below:
Add car button displaying once with Twenty Nienteen Theme
My website is www.applefix.pl. Please help me with that.
Maybe you could try to "delay" the actions after the parent theme is loaded:
function wc_move_single_product_button() {
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', 9);
};
add_action( 'after_setup_theme', 'wc_move_single_product_button', 20 );
Update: another possibility is that your theme uses another function to hook the button. I would try to use the WordPress default theme just to check if that’s the case. If it is, you can search the function and unhook it properly!
Let me know if it does the trick!

Remove Add to Cart Button from MyStile Theme in Woocommerce

I have difficulty doing this even after following instructions of how to do it. I don't know if the structure of woocommerce have changed since the below snippet was given.
Below is the code I tried using to remove the Add to cart button in the Homeapage and Shop page.
Mind you, this was pasted in the Theme Functions (functions.php) and I use MyStile Theme.
I was able to remove the Add to Cart button from the single page but not the homepage and shop page.
Code
function remove_loop_button(){
remove_action('woocommerce_before_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
}
add_action('init', 'remove_loop_button');
Thanks for your help in advance.
You can use following code. Put it in your functions.php:
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 );
To Remove “Add to Cart” button all you need to do is paste the following lines of code in your functions.php file located inside your theme’s directory.
//remove "Add to Cart" button on product listing page in WooCommerce
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' );
}

Resources