Move payment methods in Woocommerce checkout page - php

I have to move the payment methods in the checkout page of a Woocommerce website above the order review, but I don't know how. The problem is, that I tried using the following code:
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
add_action( 'woocommerce_after_order_notes', 'woocommerce_checkout_payment', 20 );
But also the "Terms and Conditions" text and the "Place order" button are moving with that. I need to have the payment options, then the order review, and in the end the "Terms and Conditions" text and the "Place order" button.
How can I do that?

Original WC Hook
// includes/wc-template-hooks.php:214
add_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
Your Hook
This will be in your theme or plugin.
// make sure the priority value is correct, running after the default priority.
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
add_action( 'woocommerce_after_order_notes', 'woocommerce_checkout_payment', 20 );
Your hook should run after WC has loaded; so that you can remove it.
function theme_wc_setup() {
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
add_action( 'woocommerce_after_order_notes', 'woocommerce_checkout_payment', 20 );
}
add_action( 'after_setup_theme', 'theme_wc_setup' );
EDIT: Thanks all, didn't know this is still actively searched. Vote up to help other devs!

Template override is necessary (not possible editing functions.php only).
One possible way to achieve what you want is:
Copy payment.php from woocommerce plugin folder to your_child _theme/woocommerce/checkout/ folder.
Open the newly created payment.php file, and add a custom hook just before the line <div class="form-row place-order">. For example:
<?php do_action( 'woocommerce_review_order_and_proceed' ); ?>
In your child theme's functions.php, add the code below to unhook woocommerce_order_review action from it's original place, and hook it to the newly created hook:
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
add_action( 'woocommerce_review_order_and_proceed', 'woocommerce_order_review', 20 );

Related

Trying to move the coupon form after "woocommerce_review_order_before_payment"

I have tried to move the coupon code to the bottom of the checkout page at hook "woocommerce_review_order_before_payment" with this code:
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
add_action( 'woocommerce_review_order_before_payment', 'woocommerce_checkout_coupon_form', 5 );
The coupon code doesn't submit, I even tried this code and it didn't solved the issue, does anyone know how to work with it?
Thanks
You can't nest the coupon form inside the checkout form. This will move the coupon form below the checkout form.
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form');
add_action( 'woocommerce_after_checkout_form', 'woocommerce_checkout_coupon_form' );
I have solved it by moving the coupon code with gift card field into the table and it worked

sale_flash badge cannot be removed from woocommerce product loop hook/action

I am trying to remove or edit the "sale!" badge is in woocommrce loop
In the content-product.php,
the comment block says the woocommerce_show_product_loop_sale_flash is hooked with woocommerce_before_shop_loop_item.
However it actually works with woocommerce_after_shop_loop_item_title.
I tried to remove everything from the hook, still, the sales badge still appears:
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating' );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price' );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash' );
The following is also not working:
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash' );
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash' );
So I really have no idea where the sales badge function is being called from?
I'm not sure why it's not working for you, because all you have to do is use remove_action, the parameters are the hook location being used and the action name. In this case:
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
This works, I checked. I was looking for the same thing. Just add it to your functions.php file. It removes the action called woocommerce_show_product_loop_sale_flash from being hooked into the woocommerce_before_shop_loop_item_title hook location.
Perhaps there is a plugin putting it there as well?
In my case, I did not want the sale flash to be inside of the link so I moved it up to be a direct child of the li instead. I did this by first removing the action via the above, and then adding a new action with a new hook location. The new hook location is the same as the one used to open the link, so I had to modify the priority number to make sure it was executed before the link action sharing the hook.
add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_show_product_loop_sale_flash', 5 );

Remove action fails to remove default WooCommerce hooked function

I am trying to move the product tabs from woocommerce_after_single_product_summary to woocommerce_before_single_product_summary. Essentially, I want to replace the image of the product on the single product with a tab that has the image gallery, but all the other tabs show up in that same container. I have issues trying to get the container around the tabs to act like the container around the image, but what's got me stumped is how to remove the tabs from the woocommerce_after_single_product_summary section. I can remove "related products" no problem, from the same section, but nothing I've done has budged the tabs.
This works fine to remove the image:
remove_action ('woocommerce_before_single_product_summary',
'woocommerce_show_product_images',20);
This works fine to add the tabs in its place (Other than the container issue):
add_action( 'woocommerce_before_single_product_summary',
'woocommerce_output_product_data_tabs', 20 );
But this never seems to get rid of the tabs:
remove_action( 'woocommerce_after_single_product_summary',
'woocommerce_output_product_data_tabs', 10 );
I've checked that 10 is the correct number (which I found does make a difference) but it IS correct. I traced the add_action to
woocommerce/includes/wc-template-hooks.php:
/**
* After Single Products Summary Div.
*
* #see woocommerce_output_product_data_tabs()
* #see woocommerce_upsell_display()
* #see woocommerce_output_related_products()
*/
add_action( 'woocommerce_after_single_product_summary',
'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_after_single_product_summary',
'woocommerce_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary',
'woocommerce_output_related_products', 20 );
I can remove related products with:
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
I've tried the suggestion (in another topic) that the hook might need a "template redirect" but that didn't work either. What I tried was:
// Trying template redirect
function esb_product_category_filter_changes()
{remove_action('woocommerce_after_single_product_summary',
'woocommerce_output_product_data_tabs', 10);
}
do_action('template_redirect','esb_product_category_filter_changes');
Any ideas? I've searched all the possibly relevant plugins, turned a bunch off, and still the same behavior. I can put the tabs anywhere I want, but I can't get rid of them.
I have tested on Storefront theme:
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
And it works. So your issue can be due to your theme or some plugins that are making some customizations on this.
How to check it: With the following hooked function you will get the raw data output for woocommerce_after_single_product_summary hook (all callbacks, with priorities and arguments). This way you will be able to see if woocommerce_output_related_products is hooked in it and what is the priority.
This testing function will output the data for admins only in archives and product pages:
add_action( 'woocommerce_before_main_content', function(){
// Only for admin user role
if( ! current_user_can('edit_products')) return;
global $wp_filter;
echo '<pre>';
print_r( $wp_filter['woocommerce_after_single_product_summary'] );
echo '</pre>';
}, 50 );
Code goes in function.php file of the active child theme (or active theme).
Now you can get the correct priority to set in the remove_action() (and remove this testing code).
You could also try the following code (without any guaranty):
add_action( 'woocommerce_after_single_product_summary', 'removing_product_tabs', 2 );
function removing_product_tabs(){
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
}
Code goes in function.php file of the active child theme (or active theme).

Unable to remove single product pages from woocommerce

I have added the following code snippet to functions.php after reseaching a lot:
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
This snippet seems to work for a lot of people.
I'm using the Salient wordpress theme, and this code snippet has no effect on the hyperlink wrap on single product grids.
Please HELP!
You should add it to a hook that proceeds when the actions have been set otherwise you won't be able to remove them. The actions should exist after the 'after_setup_theme' hook. Also ensure the hooks are removed with the same priority as they were set with.
function add_remove_hooks() {
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
}
add_action( 'after_setup_theme', 'add_remove_hooks' );

WooCommerce price position - variable product

I am trying to move position of pice in wordpress in plugin WooCommerce. In normal product its without problems as you can see here: http://beta.gaumaya.sk/?product=produkts but in variable product its almost imposiible i am trying to do it for hours right now. Here is how it looks http://beta.gaumaya.sk/?product=produkt I really need to move that price next to title. My functions.php file: add_action( 'woocommerce_single_product_summary_geril', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary_geril', 'woocommerce_template_single_price', 5 );
add_action( 'woocommerce_single_product_summary_geril', 'woocommerce_output_product_data_tabs', 20 );
add_action( 'woocommerce_single_product_summary_geril', 'woocommerce_template_single_add_to_cart', 30 );
content-single-product.php : http://pastebin.com/2DZPnnfP . How can this little thing be changed?
I would suggest removing your content-product.php from your theme and reverting back to WooCommerce's default templates. The price is pretty near the title by default.
There is no need to create your own action hook do_action( 'woocommerce_single_product_summary_geril' );? when you can simply unhook the functions you don't want from the existing hook using remove_action()?

Categories