Skip to content

Instantly share code, notes, and snippets.

@vaughanm
Created May 25, 2018 14:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaughanm/4723a8d27986583babf4b0c9887d8de5 to your computer and use it in GitHub Desktop.
Save vaughanm/4723a8d27986583babf4b0c9887d8de5 to your computer and use it in GitHub Desktop.
Mu-plugin to allow you to apply FREE shipping for specified shipping method in Marketpress, If cart total greater than set minimum,free shipping is applied.
<?php
$free_ship_minimum = 100; // minimum total for free shipping to be applied
$shipping_method = 'weight_rate'; // the shipping method for this to be applied on.
/*
* Changes the Shipping cost on the Checkout Estimated costs page
*/
add_filter( 'mp_cart/cart_meta/shipping_total', 'mp_custom_shipping_price', 88, 2);
/*
* Changes the estimated shipping total text to Free if cart total is above $free_ship_minimum
*/
function mp_custom_shipping_price( $shipping_line, $this ) {
global $mp_cart, $free_ship_minimum, $shipping_method;
$cart_total = $mp_cart->total(false) - $mp_cart->shipping_total(false);
if ($shipping_method == mp_get_setting( 'shipping->method' ) && $cart_total >= $free_ship_minimum) {
$shipping_line = '
<div class="mp_cart_resume_item mp_cart_resume_item-shipping-total">
<span class="mp_cart_resume_item_label">' . __( 'Shipping', 'mp' ) . '</span>
<span class="mp_cart_resume_item_amount">Free</span>
</div><!-- end mp_cart_resume_item-shipping-total -->';
}
return $shipping_line;
}
add_filter( 'mp_cart/total', 'mp_custom_shipping_price_total', 99, 3);
/*
* Deducts shipping total from cart Estimaed total if cart total above $free_ship_minimum
*/
function mp_custom_shipping_price_total( $total, $item_total, $this ) {
global $mp_cart, $free_ship_minimum, $shipping_method;
$cart_total = $total - $mp_cart->shipping_total(false);
if ($shipping_method == mp_get_setting( 'shipping->method' ) && $cart_total >= $free_ship_minimum) {
$custom_total = $total - $mp_cart->shipping_total(false);
}
return $custom_total;
}
/*
* Sets the shipping cost to 0 if cart total greater than $free_ship_minimum
*/
add_filter( 'mp_calculate_shipping_weight_rate', 'mp_custom_shipping_total', 100, 10 );
function mp_custom_shipping_total($custom_total, $total, $cart, $address1, $address2, $city, $state, $zip, $country, $selected_option) {
global $mp_cart, $free_ship_minimum, $shipping_method;
$cart_total = $total - $mp_cart->shipping_total(false);
if ($shipping_method == mp_get_setting( 'shipping->method' ) && $cart_total >= $free_ship_minimum) {
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment