Im doing some changes on my eshop, I have moved shipping method and payment method choices from checkout page to cart page, but now those tables have lost their auto-update functionality, and this leads to getting order errors, based on "invalid payment method". I know I need to move some action, method or anything as well to the cart page, I just cant figure out what I need to move there.
Code I have moved from checkout to cart for displaying shipping methods
<?php if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) : ?>
<?php do_action( 'woocommerce_review_order_before_shipping' ); ?>
<?php wc_cart_totals_shipping_html(); ?>
<?php do_action( 'woocommerce_review_order_after_shipping' ); ?>
<?php endif; ?>
functions.php action change
remove_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20);
add_action('order-checkout-methods', 'woocommerce_checkout_payment', 20);
Code I have moved from checkout to cart for displaying payment methods
<?php do_action('order-checkout-methods'); ?>
Problem is not in the custom function. The auto-update worked well with this, but only when it was in checkout
Any idea, what i need to add to the cart to make it work?
I see you have moved the display of shipping methods and payment methods from the checkout page to the cart page. but the issue is the auto-update functionality has been lost. that's why you need restore these.
To restore the auto-update functionality, you will need to move the relevant actions, methods, or code that handle the update of these fields to the cart page.
Related
To reduce the number of redirects on my site, i added the cart page on the same page as the checkout. and used this code to do it:
function cart_on_checkout_page_only() {
if ( is_wc_endpoint_url( 'order-received' ) ) return;
// add woocomerce cart shortcode on checkout page
echo do_shortcode('[woocommerce_cart]');
}
// Cart and Checkout same page
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page_only', 5 );
The problem is in the layout specifically, on devices it is too far from the order items as the order total is at the bottom of the page near the checkout button. I got a lot of complaints because people are too lazy to scroll down to see the coupon application in the cart at the bottom of the page
so I made the following modification:
I copied the woocommerce plugin files woocommerce/template/cart/cat.php and cart-totals.php
and pasted it into my theme in themes/mytheme/template/cart/custom-cart.php
and adapted it in the code above:
function cart_on_checkout_page_only() {
if ( is_wc_endpoint_url( 'order-received' ) ) return;
// add custom cart template on checkout page
get_template_part('template/cart/custom-cart');
}
// Cart and Checkout same page
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page_only', 5 );
my code did the job, but I believe there should be a simpler and more elegant way to make this kind of change. it's possible to make more simpler?
by the way I'm using a child storefront theme.
Problem:
on the checkout page (form-checkout.php) the following action code calls the review order AND the payment method section at the same position (after each other)
do_action('woocommerce_checkout_order_review');
However, I want the order review and payment method sections to be separate, i.e. to call them individually in different places on the checkout page.
Solution attempt:
I came across guidance here and found the file includes/wc-template-hooks.php where the above action is created with he following code:
add_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
add_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
So to test and call ONLY the payment section separately, I went back to form-checkout.php and tried this:
do_action( 'woocommerce_checkout_payment' );
or this
do_action( 'woocommerce_checkout_payment',99 );
But neither calls the payment section!
Could anyone please help me understand why this doesn't work?
Note: I know I can register hook the woocommerce_checkout_payment to a custom function and call it that way, but I'm confused as to why the direct method doesn't work and I'd prefer to keep things simple were possible.
Add this lines to functions.php in your child-theme:
// Detaching `payment` from `woocommerce_checkout_order_review` hook
remove_action('woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
// Attaching `payment` to my `woocommerce_checkout_payment_hook`
add_action('woocommerce_checkout_payment_hook', 'woocommerce_checkout_payment', 10 );
now you can use the custom hook to show the payment section:
do_action( 'woocommerce_checkout_payment_hook' );
P.S. Thank you #LoicTheAztec for the solution.
I am using the mini-cart.php file and the cart widget to show cart content and I am using AJAX add to cart standard built in WooCommerce.
Adding products to my cart works fine. I added an area to show if any coupon is added (see my code). Works all fine but when deleting the coupon I want it to be done without loading a next page. It only needs to update the mini-cart.php. Can someone help me? Basically I need some function or something which updates mini-cart.php without reloading the page.
<?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
<p>Actieve kortingscode: <?php echo esc_attr( sanitize_title( $code ) ); ?></p>
<p><?php wc_cart_totals_coupon_html( $coupon ); ?></p>
<?php endforeach; ?>
You will find the answer to your question in WooCommerce documentation
https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html
The short answer is you need to make a call to WC()->cart->remove_coupons();
As of the "how", check this SO answer (different thing but same way to resolve it)
https://stackoverflow.com/a/41593818/10864482
I designed a WooCommerce template for a customer. Now he wants to remove prices and visitors only add what they want to the list. So there will be no payment method. s:
- I can't change plugin or database. All data must remain how they are.
- I need to remove prices from all over the site. where ever they are. Cart, wishlist, single page & etc.
- I need to change payment method to something like submit list.
- at the end after submit list page there must be a contact info page.
please help.
You can hook into wc_price and remove the prices there
function my_filter_wc_price( $price ){
return '';
}
add_filter( 'wc_price', 'my_filter_wc_price' );
Then you can hook into parse_query and redirect the checkout page to the contact page.
function my_parse_query(){
if( is_page( wc_get_page_id( 'checkout' ) ) ){
wp_redirect( '/contact' );
exit;
}
}
add_action( 'parse_query', 'my_parse_query' );
That will stop people from being able purchasing things. Just hiding the price with CSS will not. They will still be able to craft URL's to add to cart, and find the cart / checkout pages.
since I found no other way I decided to do it width CSS and translation.
I removed all prices by display:none;
and I translated all the strings which are about shop and price.
Im building a webshop on Magento Platform (still localhost) and would like to have the shipping displayed in my header cart.
Currently the shipping rate is shown okay in the main cart but in the header cart it's displayed withouth tax.
This is the code of the main cart: ( the right one with tax included)
<?php echo $this->helper('checkout')->formatPrice($this->getShippingIncludeTax()) ?>
This is the code of the header cart: ( displayed without tax)
<?php echo Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingAmount(); ?>
As you can see the "getShippingIncludeTax" should be added instead of just the amount.
Any ideas how to implement this code together?
Extra:
This code also works for the header, but has the same amount withouth tax.
<?php $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
if(isset($totals['shipping']))
print __(number_format($totals['shipping']->getDat('value'),2)); ?>
would that be better ?
<?php echo Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingIncTax(); ?>
It's actually rather easy to see whats inside your object and what you can ask from it
<?php print_r(array_keys(Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData()));?>