public static function checkout($customer, $cart_info, $stripeToken)
 {
     $ufstore = UFStore::instance();
     $shipping_info = array();
     //Calculate new costs, all should be in pennies
     $cart_subtotal = UFStoreCart::getCartCost();
     $cart_shipping = $cart_info['shipping_cost'];
     $cart_total = $cart_subtotal + $cart_shipping;
     //!!!Doublecheck our new calculations match the AJAX response
     //Run the amount on stripe
     if (UFStoreCartCheckout::stripePayment($cart_total, $stripeToken)) {
         $cart = UFStoreCart::getCart();
         //Send email confirmation
         ob_start();
         // start output buffer
         include dirname(__FILE__) . '/../templates/email.php';
         $template = ob_get_contents();
         // get contents of buffer
         ob_end_clean();
         UFStoreCartCheckout::sendReceipt($customer['email'], $template);
         UFStoreCartCheckout::saveOrder($customer, $cart_info, $cart, $cart_subtotal, $cart_shipping, $cart_total);
         UFStoreCart::clearCart();
         return array('cart' => $cart, 'customer' => $customer);
     } else {
         return false;
     }
 }
 public static function getShipping($shipping_to, $country = 'United States')
 {
     $ufstore = UFStore::instance();
     $shipping_info = array();
     //Get ready to calculate for USPS
     $usps_package = array('total_cost' => 0, 'total_weight' => 0);
     $shipping_costs = array('total' => 0, 'flat' => 0, 'flat_us' => 0, 'flat_international' => 0, 'included' => 0, 'groups' => 0, 'usps' => 0);
     $groups = array();
     // Generate an array to loop through
     //Collect each cart's shipping info
     if (UFStoreCart::getCartCount() > 0) {
         foreach (UFStoreCart::getCart() as $product_id => $products) {
             foreach ($products as $product) {
                 array_push($shipping_info, array('id' => $product['unique_id'], 'price' => get_field('base_price', $product_id), 'quantity' => $product['quantity'], 'product_id' => $product_id, 'shipping_type' => get_field('shipping_type', $product_id), 'flat_rate_us' => get_field('flat_rate_us', $product_id), 'flat_rate_international' => get_field('flat_rate_international', $product_id), 'individual_weight' => get_field('product_weight', $product_id), 'total_weight' => $product['quantity'] * get_field('product_weight', $product_id), 'group_cost' => get_field('group_cost', $product_id), 'group_amount_of_product' => get_field('group_amount_of_product', $product_id), 'group_category' => get_field('group_category', $product_id)));
             }
         }
     }
     if (!empty($shipping_info)) {
         //Loop through products
         foreach ($shipping_info as $product) {
             //Total Flat Rates
             if ($product['shipping_type'] == 'flat') {
                 if ($country == 'United States') {
                     $shipping_costs['flat'] += $product['flat_rate_us'];
                     $shipping_costs['flat_us'] += $product['flat_rate_us'];
                 } else {
                     $shipping_costs['flat'] += $product['flat_rate_international'];
                     $shipping_costs['flat_international'] += $product['flat_rate_international'];
                 }
                 //Group products together
             } else {
                 if ($product['shipping_type'] == 'group') {
                     if (!array_key_exists($product['group_category'][0], $groups)) {
                         // echo $product['group_category'][0];
                         $groups[$product['group_category'][0]] = array('cost' => $product['group_cost'], 'max_amount' => $product['group_amount_of_product'], 'actual_amount' => $product['quantity']);
                     } else {
                         $groups[$product['group_category'][0]]['actual_amount'] = $groups[$product['group_category'][0]]['actual_amount'] + $product['quantity'];
                     }
                     //Total USPS Rates
                     //Don't compute this, just tally all values into a single 'package'
                 } else {
                     if ($product['shipping_type'] == 'usps') {
                         $usps_package['total_cost'] += $product['price'] * $product['quantity'];
                         $usps_package['total_weight'] += $product['total_weight'];
                     }
                 }
             }
         }
     }
     foreach ($groups as $group) {
         $shipping_costs['groups'] += (floor($group['actual_amount'] / $group['max_amount']) + 1) * $group['cost'];
         //Charge $6 for every 4 shirts
     }
     $shipping_costs['usps'] = UFStoreShippingUSPS::usps($usps_package, $country, $shipping_to);
     return $shipping_costs;
 }
Example #3
0
 protected function loadLibraries()
 {
     //General settings and what-nots
     require_once 'uf-store.acf.functions.php';
     require_once 'uf-store.ajax.functions.php';
     require_once 'uf-store.shortcode.functions.php';
     //UFStore
     require_once 'uf-store.cart.class.php';
     require_once 'uf-store.shipping.class.php';
     require_once 'uf-store.shipping.usps.class.php';
     require_once 'uf-store.checkout.class.php';
     UFStoreCart::setupCart();
     // $ufstore = UFStore::instance();
     // $ufstore->shoppingCart = new UFStoreCart();
 }
function ufstoresuccess($atts)
{
    $ufstore = UFStore::instance();
    global $content;
    ob_start();
    $cart = UFStoreCart::getCart();
    $cart_total = UFStoreCart::getCartCost();
    if (file_exists(get_template_directory() . '/ufstore/success.php')) {
        include get_template_directory() . '/ufstore/success.php';
    } else {
        include dirname(__FILE__) . '/../templates/success.php';
    }
    //Empty the shopping cart
    $wp_session['cart'] = array();
    $output = ob_get_clean();
    return $output;
}
Example #5
0
<?php

$cart = UFStoreCart::getCart();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<!-- NAME: 1 COLUMN -->
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title><?php 
echo get_field('store_title', 'option');
?>
 Order Confirmation</title>
</head>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" style="margin: 0;padding: 0;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;background-color: #F2F2F2;height: 100% !important;width: 100% !important;">
	<center>
		<table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable" style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;margin: 0;padding: 0;background-color: #F2F2F2;height: 100% !important;width: 100% !important;">
			<tr>
				<td align="center" valign="top" id="bodyCell" style="mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;margin: 0;padding: 20px;border-top: 0;height: 100% !important;width: 100% !important;">
					<!-- BEGIN TEMPLATE // -->
					<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateContainer" style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;border: 0;">
						<tr>
							<td align="center" valign="top" style="mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">
								<!-- BEGIN PREHEADER // -->
								<table border="0" cellpadding="0" cellspacing="0" width="600" id="templatePreheader" style="border-collapse: collapse;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;background-color: #FFFFFF;border-top: 0;border-bottom: 0;">
									<tr>
										<td valign="top" class="preheaderContainer" style="padding-top: 9px;mso-table-lspace: 0pt;mso-table-rspace: 0pt;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%;">
										</td>
									</tr>
								</table>
function cart_info()
{
    header('Content-Type: application/json');
    $ufstore = UFStore::instance();
    $info = array('cart_count' => UFStoreCart::getCartCount(), 'total_cost' => UFStoreCart::getCartCost());
    echo json_encode(array('cart_info' => $info));
    die;
}