Last active
January 17, 2016 17:09
-
-
Save ideag/508324393e032bcd34c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cart_notice() { | |
if ( arunas_only_virtual_products() ) { | |
return true; | |
} | |
$free_shipping_settings = get_option( 'woocommerce_free_shipping_settings' ); | |
$maximum = $free_shipping_settings['min_amount']; | |
$current = WC()->cart->subtotal; | |
$formatteddifference = wc_price( $maximum - $current ); | |
if ( $current < $maximum ) { | |
echo '<div class="woocommerce-message">' . __('Get free shipping if you order for ', 'oxygen') . $formatteddifference . __(' more!', 'oxygen').'</div>'; | |
} | |
} | |
add_action( 'woocommerce_cart_contents', 'cart_notice' ); | |
add_action( 'woocommerce_review_order_before_payment', 'cart_notice' ); | |
function arunas_only_virtual_products() { | |
$all_virtual_products = false; | |
$virtual_products = 0; | |
$products = WC()->cart->get_cart(); | |
// Loop through cart products | |
$all_products = sizeof( $products ); | |
foreach( $products as $product ) { | |
$product = wc_get_product( $product['product_id'] ); | |
if( $product->is_virtual() ) { | |
$virtual_products += 1; | |
} | |
} | |
if( $all_products == $virtual_products ) { | |
$all_virtual_products = true; | |
} | |
return $all_virtual_products; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment