public function vtprd_woo_maybe_load_discount_amount_to_coupon($status, $code)
 {
     //error_log( print_r(  'Function begin - vtprd_woo_maybe_load_discount_amount_to_coupon', true ) );
     //v1.1.1 begin -
     // "do_no_actions" set/unset in function  vtprd_build_product_price_array
     if (!isset($_SESSION)) {
         session_start();
         header("Cache-Control: no-cache");
         header("Pragma: no-cache");
     }
     if (isset($_SESSION['do_no_actions']) && $_SESSION['do_no_actions']) {
         return;
     }
     //v1.1.1 end
     global $vtprd_rules_set, $wpdb, $vtprd_cart, $vtprd_setup_options, $vtprd_info, $woocommerce;
     //v1.0.9.1 begin
     if ($vtprd_setup_options['discount_taken_where'] != 'discountCoupon') {
         return;
         //v1.1.0.2
     }
     //v1.0.9.1 end
     vtprd_debug_options();
     //v1.0.5
     if ($code != $vtprd_info['coupon_code_discount_deal_title']) {
         return;
         //v1.1.0.2
     }
     //Open Session Variable, get rules_set and cart if not there....
     $data_chain = $this->vtprd_get_data_chain();
     if ($vtprd_cart->yousave_cart_total_amt <= 0) {
         return false;
     }
     //v1.0.7.4 begin
     //v1.0.9.3 moved      vtprd_load_cart_total_incl_excl();
     //$apply_before_tax  used to MIMIC the way regular coupons taxation!!
     //  Testing Note:  Compare how Deal discount is applied vs Regular coupon discount of same amount
     //    example: 10% cart discount vs 10% coupon, with a variety of tax switch settings...
     $apply_before_tax = vtprd_coupon_apply_before_tax();
     //      $apply_before_tax = '';
     //v1.0.7.4 end
     //GET coupon_id of the previously inserted placeholder coupon where title = $vtprd_info['coupon_code_discount_deal_title']
     $deal_discount_title = $vtprd_info['coupon_code_discount_deal_title'];
     $coupon_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_title ='" . $deal_discount_title . "'  AND post_type = 'shop_coupon' AND post_status = 'publish'  LIMIT 1");
     //defaults take from  class/class-wc-coupon.php    function __construct
     //v1.0.9.3 redone begin
     $current_version = WOOCOMMERCE_VERSION;
     //AFTER Woo 2.3, coupon is always applied PRE_TAX i
     if (version_compare(strval('2.3.0'), strval($current_version), '>') == 1) {
         //'==1' = 2nd value is lower
         //pre woo 2.3
         vtprd_load_cart_total_incl_excl();
         $coupon_data = array('id' => $coupon_id, 'type' => 'fixed_cart', 'amount' => $vtprd_cart->yousave_cart_total_amt, 'individual_use' => 'no', 'product_ids' => array(), 'exclude_product_ids' => array(), 'usage_limit' => '', 'usage_count' => '', 'expiry_date' => '', 'apply_before_tax' => $apply_before_tax, 'free_shipping' => 'no', 'product_categories' => array(), 'exclude_product_categories' => array(), 'exclude_sale_items' => 'no', 'minimum_amount' => '', 'customer_email' => '');
     } else {
         if (get_option('woocommerce_calc_taxes') == 'yes' && get_option('woocommerce_prices_include_tax') == 'yes') {
             //$amount = $vtprd_cart->yousave_cart_total_amt;
             $amount = $vtprd_cart->yousave_cart_total_amt_incl_tax;
         } else {
             $amount = $vtprd_cart->yousave_cart_total_amt_excl_tax;
         }
         $coupon_data = array('id' => $coupon_id, 'discount_type' => 'fixed_cart', 'coupon_amount' => $amount, 'individual_use' => 'no', 'product_ids' => array(), 'exclude_product_ids' => array(), 'usage_limit' => '', 'usage_limit_per_user' => '', 'limit_usage_to_x_items' => '', 'usage_count' => '', 'expiry_date' => '', 'free_shipping' => 'no', 'product_categories' => array(), 'exclude_product_categories' => array(), 'exclude_sale_items' => 'no', 'minimum_amount' => '', 'maximum_amount' => '', 'customer_email' => array());
     }
     return $coupon_data;
 }
Example #2
0
function vtprd_checkout_cart_reporting($msgType)
{
    //v1.0.8.0
    global $vtprd_cart, $vtprd_cart_item, $vtprd_rules_set, $vtprd_info, $vtprd_setup_options, $woocommerce;
    $output = '';
    //v1.0.7.9
    if ($vtprd_setup_options['show_checkout_discount_detail_lines'] == 'yes' || $vtprd_setup_options['show_checkout_discount_total_line'] == 'yes' || $vtprd_setup_options['checkout_new_subtotal_line'] == 'yes') {
        $output .= '<table class="shop_table cart vtprd_shop_table" cellspacing="0">';
        $output .= '<thead>';
        $output .= '<tr class="checkout_discount_headings">';
        $output .= '<th  class="product-name" >' . __('Discount Product', 'vtprd') . '</th>';
        $output .= '<th  class="product-quantity">' . __('Quantity', 'vtprd') . '</th>';
        //v1.0.9.0 added new title
        if ($vtprd_setup_options['discount_taken_where'] == 'discountCoupon') {
            $output .= '<th  class="product-subtotal" >' . __('Discount Amount', 'vtprd') . '</th>';
        } else {
            $output .= '<th  class="product-subtotal" >' . __('Discount', 'vtprd') . '<br>' . __('( in Unit Price )', 'vtprd') . '</th>';
        }
        $output .= '</tr>';
        $output .= '</thead>';
    }
    vtprd_load_cart_total_incl_excl();
    //v1.0.7.4
    if ($vtprd_setup_options['show_checkout_discount_total_line'] == 'yes' || $vtprd_setup_options['checkout_new_subtotal_line'] == 'yes') {
        $output .= '<tfoot>';
        if ($vtprd_setup_options['show_checkout_discount_total_line'] == 'yes') {
            //v1.0.8.9a begin
            // pick up included, excluded or yousave_cart_total_amt Total
            $amt = vtprd_load_cart_total_incl_excl();
            //$amt = vtprd_format_money_element($vtprd_cart->yousave_cart_total_amt);
            $amt = vtprd_format_money_element($amt);
            //v1.0.8.9a end
            $amt .= vtprd_maybe_load_incl_excl_vat_lit();
            //v1.0.7.4
            $output .= '<tr class="checkout_discount_total_line">';
            $output .= '<th scope="row" colspan="2">' . $vtprd_setup_options['checkout_credit_total_title'] . '</th>';
            $output .= '<td ><span class="amount">' . $vtprd_setup_options['checkout_credit_total_label'] . $amt . '</span></td>';
            $output .= '</tr>';
        }
        if ($vtprd_setup_options['checkout_new_subtotal_line'] == 'yes') {
            //can't use the regular routine ($subtotal = vtprd_get_Woo_cartSubtotal(); ), as it returns a formatted result
            if ($woocommerce->cart->tax_display_cart == 'excl') {
                $subtotal = $woocommerce->cart->subtotal_ex_tax;
            } else {
                $subtotal = $woocommerce->cart->subtotal;
            }
            //v1.0.8.9a begin
            // pick up included, excluded or yousave_cart_total_amt Total
            //$subtotal -= $vtprd_cart->yousave_cart_total_amt;
            $subtotal -= vtprd_load_cart_total_incl_excl();
            $amt = vtprd_format_money_element($subtotal);
            //v1.0.8.9a end
            $amt .= vtprd_maybe_load_incl_excl_vat_lit();
            //v1.0.7.4
            $output .= '<tr class="checkout_new_subtotal">';
            $output .= '<th scope="row" colspan="2">' . $vtprd_setup_options['checkout_new_subtotal_label'] . '</th>';
            $output .= '<td ><span class="amount">' . $amt . '</span></td>';
            $output .= '</tr>';
        }
        $output .= '</tfoot>';
    }
    $output .= '<tbody>';
    //new
    if ($vtprd_setup_options['show_checkout_purchases_subtotal'] == 'beforeDiscounts') {
        $amt = vtprd_get_Woo_cartSubtotal();
        $output .= '<tr class="checkout_purchases_subtotal">';
        $output .= '<th scope="row" colspan="2">' . $vtprd_setup_options['checkout_credit_subtotal_title'] . '</th>';
        $output .= '<td ><span class="amount">' . $amt . '</span></td>';
        $output .= '</tr>';
    }
    if ($vtprd_setup_options['show_checkout_discount_detail_lines'] == 'yes') {
        //get the discount details
        $output .= vtprd_checkout_cart_discount_rows($msgType);
    }
    if ($vtprd_setup_options['show_checkout_purchases_subtotal'] == 'withDiscounts') {
        $amt = vtprd_get_Woo_cartSubtotal();
        $output .= '<tr class="checkout_purchases_subtotal">';
        $output .= '<th scope="row" colspan="2">' . $vtprd_setup_options['checkout_credit_subtotal_title'] . '</th>';
        $output .= '<td ><span class="amount">' . $amt . '</span></td>';
        $output .= '</tr>';
    }
    $output .= '</tbody>';
    $output .= '</table>';
    echo $output;
    return;
}