public function vtwpr_get_product_catalog_price_add_to_cart($product_id, $parameters, $cart)
 {
     global $vtwpr_info;
     $session_found = vtwpr_maybe_get_product_session_info($product_id);
     // $session_found MEANS ($vtwpr_info['product_session_info']['product_discount_price'] > 0)
     if ($session_found) {
         foreach ($cart->cart_items as $key => $cart_item) {
             if ($cart_item->product_id == $product_id) {
                 if ($vtwpr_info['product_session_info']['product_discount_price'] != $cart_item->unit_price) {
                     $cart_item->unit_price = $vtwpr_info['product_session_info']['product_discount_price'];
                     $cart_item->total_price = $cart_item->quantity * $cart_item->unit_price;
                 }
             }
         }
     }
 }
Example #2
0
function vtwpr_load_vtwpr_cart_for_processing()
{
    global $post, $wpdb, $woocommerce, $vtwpr_cart, $vtwpr_cart_item, $vtwpr_setup_options, $vtwpr_info;
    // from Woocommerce/templates/cart/mini-cart.php  and  Woocommerce/templates/checkout/review-order.php
    $woocommerce_cart_contents = $woocommerce->cart->get_cart();
    if (sizeof($woocommerce_cart_contents) > 0) {
        $vtwpr_cart = new vtwpr_Cart();
        foreach ($woocommerce_cart_contents as $cart_item_key => $cart_item) {
            $_product = $cart_item['data'];
            if ($_product->exists() && $cart_item['quantity'] > 0) {
                $vtwpr_cart_item = new vtwpr_Cart_Item();
                //the product id does not change in woo if variation purchased.
                //  Load expected variation id, if there, along with constructed product title.
                $varLabels = ' ';
                if ($cart_item['variation_id'] > ' ') {
                    // get parent title
                    $parent_post = get_post($cart_item['product_id']);
                    // get variation names to string onto parent title
                    foreach ($cart_item['variation'] as $key => $value) {
                        $varLabels .= $value . ' ';
                    }
                    $vtwpr_cart_item->product_id = $cart_item['variation_id'];
                    $vtwpr_cart_item->variation_array = $cart_item['variation'];
                    $vtwpr_cart_item->product_name = $parent_post->post_title . ' ' . $varLabels;
                    $vtwpr_cart_item->parent_product_name = $parent_post->post_title;
                } else {
                    $vtwpr_cart_item->product_id = $cart_item['product_id'];
                    $vtwpr_cart_item->product_name = $_product->get_title() . $woocommerce->cart->get_item_data($cart_item);
                }
                $vtwpr_cart_item->quantity = $cart_item['quantity'];
                $product_id = $vtwpr_cart_item->product_id;
                //***always*** will be a session found
                //$session_found = vtwpr_maybe_get_product_session_info($product_id);
                vtwpr_maybe_get_product_session_info($product_id);
                //By this time, there may  be a 'display' session variable for this product, if a discount was displayed in the catalog
                //  so 2nd - nth iteration picks up the original unit price, not any discount shown currently
                //  The discount is applied in apply-rules for disambiguation, then rolled out before it gets processed (again)     product_discount_price
                if ($vtwpr_info['product_session_info']['product_discount_price'] > 0) {
                    $vtwpr_cart_item->unit_price = $vtwpr_info['product_session_info']['product_unit_price'];
                    $vtwpr_cart_item->db_unit_price = $vtwpr_info['product_session_info']['product_unit_price'];
                    $vtwpr_cart_item->db_unit_price_special = $vtwpr_info['product_session_info']['product_special_price'];
                    $vtwpr_cart_item->db_unit_price_list = $vtwpr_info['product_session_info']['product_list_price'];
                } else {
                    //vat_exempt seems to be the same as tax exempt, using the same field???
                    //  how does this work with taxes included in price?
                    //  how about shipping includes taxes, then roll out taxes (vat_exempt) ???
                    //FROM my original plugins:  $vtwpr_cart_item->unit_price     =  get_option( 'woocommerce_display_cart_prices_excluding_tax' ) == 'yes' || $woocommerce->customer->is_vat_exempt() ? $_product->get_price_excluding_tax() : $_product->get_price();
                    //FROM woo cart		$product_price = get_option( 'woocommerce_tax_display_cart' ) == 'excl' ? $_product->get_price_excluding_tax() : $_product->get_price_including_tax();
                    //  combining the two:::
                    //DON'T USE THIS ANYMORE, BECOMES SELF-REFERENTIAL, AS GET_PRICE() NOW HOOKS THE SINGLE PRODUCT DISCOUNT ...
                    //    $vtwpr_cart_item->unit_price     =  get_option( 'woocommerce_tax_display_cart' ) == 'excl' || $woocommerce->customer->is_vat_exempt() ? $_product->get_price_excluding_tax() : $_product->get_price();
                    //v1.0.3 begin - redo for VAT processing...
                    $regular_price = get_post_meta($product_id, '_regular_price', true);
                    if ($regular_price > 0) {
                        $vtwpr_cart_item->db_unit_price_list = $regular_price;
                    } else {
                        $vtwpr_cart_item->db_unit_price_list = get_post_meta($product_id, '_price', true);
                    }
                    $vtwpr_cart_item->db_unit_price_special = get_post_meta($product_id, '_sale_price', true);
                    if (get_option('woocommerce_prices_include_tax') == 'no' || $woocommerce->customer->is_vat_exempt()) {
                        //NO VAT included in price
                        $vtwpr_cart_item->unit_price = $cart_item['line_subtotal'] / $cart_item['quantity'];
                    } else {
                        //VAT included in price, and $cart_item pricing has already subtracted out the VAT, so use DB prices (otherwise if other functions called, recursive processing will ensue...)
                        switch (true) {
                            case $vtwpr_cart_item->db_unit_price_special > 0:
                                if ($vtwpr_cart_item->db_unit_price_list < 0 || $vtwpr_cart_item->db_unit_price_special < $vtwpr_cart_item->db_unit_price_list) {
                                    //item is on sale, use sale price
                                    $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_special;
                                } else {
                                    //use regular price
                                    $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_list;
                                }
                                break;
                            default:
                                $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_list;
                                break;
                        }
                        /*
                        if ( ($vtwpr_cart_item->db_unit_price_special > 0) &&
                             ($vtwpr_cart_item->db_unit_price_special < $vtwpr_cart_item->db_unit_price_list) ) {
                          $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_special;
                        } else {
                          $vtwpr_cart_item->unit_price = $vtwpr_cart_item->db_unit_price_list;
                        }
                        */
                    }
                    $vtwpr_cart_item->db_unit_price = $vtwpr_cart_item->unit_price;
                    //v1.0.3 end
                }
                // db_unit_price_special CAN be zero if item is FREE!!
                if ($vtwpr_cart_item->unit_price < $vtwpr_cart_item->db_unit_price_list) {
                    $vtwpr_cart_item->product_is_on_special = 'yes';
                }
                $vtwpr_cart_item->total_price = $vtwpr_cart_item->quantity * $vtwpr_cart_item->unit_price;
                /*  *********************************
                 ***  JUST the cat *ids* please...
                 ************************************ */
                $vtwpr_cart_item->prod_cat_list = wp_get_object_terms($cart_item['product_id'], $vtwpr_info['parent_plugin_taxonomy'], $args = array('fields' => 'ids'));
                $vtwpr_cart_item->rule_cat_list = wp_get_object_terms($cart_item['product_id'], $vtwpr_info['rulecat_taxonomy'], $args = array('fields' => 'ids'));
                //initialize the arrays
                $vtwpr_cart_item->prod_rule_include_only_list = array();
                $vtwpr_cart_item->prod_rule_exclusion_list = array();
                /*  *********************************
                 ***  fill in include/exclude arrays if selected on the PRODUCT Screen (parent plugin)
                 ************************************ */
                $vtwpr_includeOrExclude_meta = get_post_meta($cart_item['product_id'], $vtwpr_info['product_meta_key_includeOrExclude'], true);
                //v1.0.4  use the parent ID at all times!
                if ($vtwpr_includeOrExclude_meta) {
                    switch ($vtwpr_includeOrExclude_meta['includeOrExclude_option']) {
                        case 'includeAll':
                            break;
                        case 'includeList':
                            $vtwpr_cart_item->prod_rule_include_only_list = $vtwpr_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeList':
                            $vtwpr_cart_item->prod_rule_exclusion_list = $vtwpr_includeOrExclude_meta['includeOrExclude_checked_list'];
                            break;
                        case 'excludeAll':
                            $vtwpr_cart_item->prod_rule_exclusion_list[0] = 'all';
                            //set the exclusion list to exclude all
                            break;
                    }
                }
                //add cart_item to cart array
                $vtwpr_cart->cart_items[] = $vtwpr_cart_item;
            }
        }
        //	endforeach;
    }
    //end  if (sizeof($woocommerce->cart->get_cart())>0)
    if (defined('VTWPR_PRO_DIRNAME') && $vtwpr_setup_options['use_lifetime_max_limits'] == 'yes') {
        vtwpr_get_purchaser_info_from_screen();
    }
    $vtwpr_cart->purchaser_ip_address = $vtwpr_info['purchaser_ip_address'];
}