My woocommerce shop is UK based, selling bulky items to both the UK market and internationally using FedEx.
I use FedEx for international shipping but sometimes an address cannot be shipped to and the customer gets the 'no shipping available' message. However, as far as I can tell, Woocommerce STILL allows the customer to place the order in these situations resulting in an order that cannot be fulfilled. Is there a simple setting somewhere that I am missing that says if no shipping is available, don't let the order be placed?
I did find this resource - https://www.bolderelements.net/support/knowledgebase/removing-checkout-button-shipping-not-available/ but that only removes the ability to get to the checkout page.
It seems like there should be a setting for something this basic?
I ended up solving this by not hiding the button, but by forcing an error if there is no shipping. I'm using the woocommerce_checkout_process action for this:
function is_valid_shipping() {
$selected_shipping = WC()->session->get('chosen_shipping_methods');
if(in_array(false, $selected_shipping)){
wc_add_notice( __( 'Your Shipping is not valid.' ), 'error' );
}
}
add_action( 'woocommerce_checkout_process', 'is_valid_shipping' );
Hope this helps someone else!
Related
I hope someone can kindly help with our Woocommerce problem.
I've been stuck looking for examples on how to display an ACF (Advanced Customs Field) field on the Orders Details Page. The difference with my query to others is that the ACF field is set against user information. So in the ACF Field group, I have set "User Role" "is equal" to "All". This works fine and the field can be seen when viewing USERS in the backend. Via the ACF plugin, it will save data against the user.
The field label is "Credit Account Status", and field name is "credit_account_status". Its a checkbox field with 3 options:
Active - No credit given
Active - Credit OK
ON STOP - credit removed; see Accounts Dept.
We want to call up this field when viewing orders on the Order Details page - maybe underneath the shipping address section at the top of the order page. We want this as a visual to prevent us raising new orders manually for someone who hasnt paid their bills on time!
Can anyone help please?
I previously tried to edit the below code, but my programming is very poor - this code seems to bring in data from Order meta, not USER meta.
/**
Display field value on the admin order edit page..
PHP Custom Feild Value
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo ''.__('Store Location').': ' . get_post_meta( $order->id, 'My Field', true ) . '';
}
Best wishes, Craig
I use this plugin: https://wordpress.org/plugins/aramex-shipping-woocommerce/
But I try any means but I failed to solve the issue . I have active Aramex account with all details, I setup plugin in woocommerce settings, but after click view cart show Aramex: ERR52 - Destination my city and address are invalid while I start shop as a guest. Also is it possible to disable ZIP code while use Aramex? Please any one with idea what cause this
the zipcode requirements are based on each country , for eg: GCC countries do not need zip code and most other countries need zipcode.
You can have WooCommerce override the default setting that makes the field required by adding a filter to your theme's functions.php. It would be best practice is to create a child theme so it won't get overwritten each time you update the theme.
For example, this code will remove the "required" state from the billing and shipping postal codes during checkout (if the shipping country is not 'US'):
add_filter( 'woocommerce_checkout_fields','custom_override_default_address_fields' );
function custom_override_default_address_fields($fields){
global $woocommerce;
$country = $woocommerce->customer->get_shipping_country();
if($country !== 'US'){
$fields['billing']['billing_postcode']['required'] = false;
$fields['shipping']['shipping_postcode']['required'] = false;
}
return $fields;
}
For more details on filters and fields available to edit via filtering see WooCommerce Customizing checkout fields using actions and filters doc
I’ve added the following filter (see below) for the scenario that a customer adds another (individually sold, digital) product to the cart that is already in the cart.
It was a nice way to disable the kind of ugly “you cannot add another product” message in a case that happened and just show the cart (as a reminder that the product is already in the cart)
With the new 3.7 woocommerce update, the appearing circle on top of the ajax "buy button" is stuck in an endlessly spinning loop.
In the version before the circle started spinning, it stopped, the cart appeared to show the customer that the product is already in the cart.
Did woocommerce change the variables that are involved in the filter below or is there another easy fix that I'm not aware of?
// if product is already in cart, just go to cart and don’t show ugly “you cannot add another product” message
add_filter( ‘woocommerce_add_to_cart_sold_individually_found_in_cart’, ‘spark_redirect_to_cart’ );
function spark_redirect_to_cart( $found_in_cart ) {
if ( $found_in_cart ) {
wp_safe_redirect( wc_get_page_permalink( ‘cart’ ) );
exit;
}
return $found_in_cart;
}
Help is very much appreciated, thanks.
Or is this bug related to the flatsome theme I'm using.
For those shipping methods, I would like to have:
"Free shipping" only for Cash-on-delivery (COD) payment method (I just renamed it to other label but I am using the COD gateway).
"Flat rate" for other payment gateways (excluding COD payment method of course).
My question: How do I make a specific payment gateway to be free shipping when selected?
For example like in this screenshot:
Similar unanswered question: Woocommerce free shipping based on payment gateway selected
WooCommerce requires that shipping is selected before a gateway, this is how COD works because it checks if an enabled shipping method is selected before providing COD as an option. So if the COD method does not work for you then there is no other way to accomplish this because you are asking the checkout process work backwards from how it was designed.
You can not modify shipping once a payment gateway has been selected due to the way WooCommerce works. You can only add extra fees within the code for each gateway.
After a while of thinking about it, I got curious and thought i'd have a play to see if it was truely impossible. It turns out that with a bit of crude hacking you can actually get this to work, here is a basic plugin that will accomplish the task:
<?php
/**
* Plugin Name: Free Shipping For BACS
* Description: Makes shipping for BACS free.
* Version: 0.0.1
* Author: Kodaloid
* Requires at least: 4.4
* Tested up to: 4.8
*/
if (!defined('ABSPATH')) exit;
add_action('init', 'fg_init');
function fg_init() {
add_action('woocommerce_cart_calculate_fees', 'fg_add_fee');
add_action('wp_footer', 'fg_footer', 9999);
}
function fg_footer() {
?>
<script type="text/javascript">
jQuery(function($) {
setInterval(function() {
$(".input-radio[name='payment_method']").off().change(function() {
console.log('triggered');
jQuery('body').trigger('update_checkout');
});
}, 500);
});
</script>
<?php
}
function fg_add_fee($the_cart) {
global $woocommerce;
if ($woocommerce->session->chosen_payment_method == 'bacs') {
$woocommerce->cart->add_fee('Free Shipping For BACS', -($the_cart->shipping_total), true, 'standard');
}
}
Save the code above as free_shipping_for_bacs.php and install the plugin using the Upload Plugin feature in WordPress.
Basically what this does is check the session to see which payment method has been picked, then if the bacs method is chosen adds a fee which is minus the total of the shipping. This works but because the cart updates using AJAX you need to trigger the update_checkout event attached to the body in JavaScript every time the payment method changes in order to see the change reflected in the cart above.
So as a hack I have added a loop that re-adds the change handler every 500ms to the footer event (if your theme does not implement wp_footer hook, make sure to add it), this can and should be improved upon if you decide to use this code as there are better methods to check if the change event needs re-adding, it's just I don't have a lot of time today.
Koda
So basically, what i want, to show product added in cart also on archive page. I did this functionality, you can refer with image (1 item- already in cart) but my code work on refresh the page. I want to show the same with ajax. As soon as "add to cart" clicked, the data added in mini cart, at same time data will show on product listing page. enter image description here
Go to
Woocommerce > Settings > Products > Enable AJAX add to cart buttons on archives
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
global $woocommerce;
$return_to = get_permalink(woocommerce_get_page_id('shop'));
$message = sprintf('%s %s', $return_to, __('Continue Shopping', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
return $message;
}
If you want to add your product with quantity using Ajax then definitely WooCommerce default checkbox Enable AJAX to add to cart buttons on archives not works for quantity purpose.
There are many solutions to add this feature. I have implemented it earlier. You just need to add some classes, functions, and script to achieve this.
This is the link which is really helpful for me and you can go through it or you can also check this one. It's not complicated.
If you want to add this in your headers like a mini cart or something. So for that, this one is the best solution for you.
Hope this will helpful for you. Thanks.