Showing posts with label Woocommerce useful codes. Show all posts
Showing posts with label Woocommerce useful codes. Show all posts

Free Shipping Threshold @ Cart Page

 /**

 * @snippet       Free Shipping Threshold @ Cart Page
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=111758
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_action( 'woocommerce_before_cart', 'bbloomer_free_shipping_cart_notice' );
  
function bbloomer_free_shipping_cart_notice() {
   $threshold = 80;
   $current = WC()->cart->get_subtotal();
   if ( $current < $threshold ) {
      wc_print_notice( 'Get free shipping if you order ' . wc_price( $threshold - $current ) . ' more!', 'notice' );
   }
}

BOGO

 /**

 * @snippet       BOGO
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=111758
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_filter( 'woocommerce_add_to_cart_validation', 'bbloomer_bogo', 10, 3 );
  
function bbloomer_bogo( $passed, $product_id, $quantity ) {
   $sku_with_gift = 'sku0001';
   $sku_free_gift = 'sku0002';
   $product = wc_get_product( $product_id );
   $sku_this = $product->get_sku();
    if ( $sku_this == $skuswithgift ) {
       WC()->cart->add_to_cart( wc_get_product_id_by_sku( $sku_free_gift ) );
   }
   return $passed;
}

Product Add-ons @ Single Product Page

 /**

 * @snippet       Product Add-ons @ Single Product Page
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=111758
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_gift_wrap', 35 );
   
function bbloomer_gift_wrap() {   
   ?>
   <label><input type="checkbox" name="gift-wrap" value="Yes">$2 Gift Wrap?</label>
    <?php
}
   
add_filter( 'woocommerce_add_cart_item_data', 'bbloomer_store_gift', 10, 2 );
   
function bbloomer_store_gift( $cart_item, $product_id ) {
   if( isset( $_POST['gift-wrap'] ) ) $cart_item['gift-wrap'] = $_POST['gift-wrap'];
   return $cart_item;
}
 
add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_add_checkout_fee' );
  
function bbloomer_add_checkout_fee() {
   foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
        if ( isset( $cart_item['gift-wrap'] ) ) {
            $itsagift = true;
            break;
        }
    }
    if ( $itsagift == true ) WC()->cart->add_fee( 'Gift Wrap', 2 );
}

Free Shipping Threshold @ Cart Page