What's the best way to set up a flat rate shipping fee up to a certain dollar amount, and then free shipping over that dollar amount? I'd like to set it up like this: $15 shipping for all items in their cart if cart is less than $50, free shipping on orders over $50. Thanks!
You can achieve this with following way
Config the flat rate in WooCommerce zone
Config the Free shipping with minimum order amount $50
Use below code snippet to hide Flate rate if the cart total is above $50
add_filter('woocommerce_package_rates', 'hide_flat_rate_based_on_cart_total', 10, 3);
function hide_flat_rate_based_on_cart_total( $available_shipping_methods, $package ){
$price_limit = 50;
if( WC()->cart->get_total() > $price_limit ){
foreach($available_shipping_methods as $method_key => $method){
if ( strpos($method->method_id, 'flat_rate' ) !== false) {
unset($available_shipping_methods[$method_key]);
}
}
}
return $available_shipping_methods;
}
Related
I run an eCommerce site that sells food and drink. Most food products are charged 0% VAT here in Ireland so I'm wondering if there's a way of changing the default tax rate to Zero in the Product section in WooCommerce. This would avoid me having to change it for the odd product that does require either Reduced or Standard rates. I'm currently using the following code to make the default Non-taxable but this disables the Zero numbers on the monthly reports (which Revenue needs to see). Any other options?
add_action('woocommerce_product_options_tax', 'new_product_tax_status_none');
function new_product_tax_status_none()
{
global $post, $pagenow;
// Only on new product pages
if( $pagenow === 'post-new.php' ) :
?>
<script>
jQuery(function($){
// On load set the tax status to none
$('select[name="_tax_status"]').val('none');
});
</script>
<?php
endif;
}
I would like to create a plugin to add 2 shortcodes to my woocommerce shop so I can add the shipping cost as shortcode in text like this example:
Our shipping costs to Amsterdam is [shipping_cost_1] Euro
So on front end the text will be like this: Our shipping costs to Amsterdam is 6,95 Euro
These are the rates and shortcodes I want to use:
[shipping_cost_1] = flat rate woocommerce shipping cost including VAT for shipping zone 1 (shipping inside Amsterdam)
[shipping_cost_2] = flat rate woocommerce shipping cost including VAT for shipping zone 2 (shipping outside Amsterdam)
For reference, this is where the shipping costs for Amsterdam are displayed on the checkout page:
I would like to add the code in the following structure:
// The shortcode function
function shipping_cost_display_1() {
// Get shipping cost from woocommerce
???
// Ad code returned
???
// Register shortcode
add_shortcode('shipping_cost_1', 'shipping_cost_display_1');
just wondering if you checked this article already: WooCommerce: Show Shipping Rates # Single Product Page?
Basically you can get the shipping zones with a simple command:
WC_Shipping_Zones::get_zones();
Once you have them, you can loop over the array and find rates inside ($instance['cost']).
The following should do the trick for you - of course change "amsterdam" to your desired zone name:
function shipping_cost_display_1() {
$zones = WC_Shipping_Zones::get_zones();
foreach ( $zones as $zone_id => $zone ) {
if ( "amsterdam" !== $zone['zone_name'] ) continue;
$zone_shipping_methods = $zone['shipping_methods'];
foreach ( $zone_shipping_methods as $index => $method ) {
$instance = $method->instance_settings;
return $instance['cost'];
}
}
}
add_shortcode( 'shipping_cost_1', 'shipping_cost_display_1' );
There is also to say that the same shortcode could be used to return the two rates, by using a shortcode parameter.
Our customer currently sells artificial grass and has 3 different shipping zones set up depending on where in the UK the order is being shipped.
They’ve now decided to also sell accessories, but they want the shipping to work the following way:
A flat delivery cost on any purchase of these accessories nationwide
will be £10 if the customer is purchasing accessories only (no grass
sale). If the customer is purchasing a grass sale and accessories at
the same time then there will only be the grass delivery charge to be
added as they will be delivered at the same time.
Is this possible?
I have found a solution, I added the following code to my functions.php file in my child theme:
add_filter('woocommerce_package_rates', 'specific_products_shipping_methods', 10, 2);
function specific_products_shipping_methods($rates, $package) {
$terms = array('grass');
$taxonomy = 'product_cat';
$method_instances_ids = array('flat_rate:9', 'flat_rate:10', 'flat_rate:11');
$found = false;
foreach($package['contents'] as $cart_item) {
if (has_term($terms, $taxonomy, $cart_item['product_id'])) {
$found = true;
break;
}
}
if (! $found) return $rates;
foreach($rates as $rate_id => $rate) {
if (in_array($rate_id, $method_instances_ids)) {
unset($rates[$rate_id]);
}
}
return $rates;
}
This hides the accessories shipping options if there is a grass product in the cart.
Using Woocommerce plugin.
I get this code to add Tax based in the buyer rol.
It works fine but the Tax is only applied to product price. I also need to apply the same Tax to the Shipping cost.
I guess I need to use another filter parameter but I don't know which one.
Here is the real code:
function wc_re_eq( $tax_class, $product ) {
if ( is_user_logged_in() && current_user_can( 'client_re' ) ) {
$tax_class = 'R.E';
}
return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'wc_re_eq', 1, 2 );
You should be applying that in your tax rate chart. There is a checkbox for shipping, where you apply tax to shipping.
WooCommerce documentation: https://docs.woocommerce.com/document/setting-up-taxes-in-woocommerce/#tax-rate-examples
#Jpash do you solve it?
Through the label "R.E.", I get the feeling that your problem is related to "recargo de equivalencia" of Spain.
I have the same problem. For certain users I must apply another type of tax only for the shipping costs.
I am providing renting service online in my woocommerce website i want to charge only for refundable amount , but wants to also show the product amount, but while customer goes to view cart. there are products total shown in subtotal I want the final total amount in which the product total amount is excluded only refundable amount is included
General Cart:- $total=$subtotal+$refundable
I need :- $total=$refundable
How can i do that
Try adding your refund as a custom fee. Please refer this example
function woo_add_cart_fee() {
global $woocommerce;
$woocommerce->cart->add_fee( __('Refundable deposit', 'woocommerce'), -3750.00 );
// since its going to be refund we should add fee in negative value.
// You can add the refund as fee in this hook
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );