function custom_add_tax($instance) { if (is_admin() && !defined('DOING_AJAX')) { return; } global $woocommerce; $fee = 0; foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) { $product = new WC_Product($values['product_id']); $sku = $product->get_sku(); $qty = $values['quantity']; include_once TEMPLATEPATH . "/portal/api/Api.php"; include_once TEMPLATEPATH . "/portal/api/Setting.php"; include_once TEMPLATEPATH . "/portal/api/RequestParams.php"; include_once TEMPLATEPATH . "/portal/api/BQ_Base.php"; include_once TEMPLATEPATH . "/portal/api/BQ_CustomerManualInvoiceQuoteRequest.php"; $Api = new Api(); $requestParams = new requestParams(); $BQ = new BQ_CustomerManualInvoiceQuoteRequest(); // $BQ->set_billingProfileId('3'); $BQ->set_customerId(WC()->session->get('customerId')); $skus = array($sku); $BQ->set_Skus($skus); $requestParams->id = Setting::CLEC_ID; $requestParams->firstName = Setting::CLEC_FIRSTNAME; $requestParams->lastName = Setting::CLEC_LASTNAME; $requestParams->details = $BQ; $request = $Api->buildRequest($requestParams); $Api->callAPI(Setting::URL, $request); $BQ->set_response($Api->response); // echo '<pre>' . var_export( $BQ->get_response(), true ) . '</pre>'; // echo '<pre>' . var_export( $BQ->get_tax_total(), true ) . '</pre>'; $fee += $BQ->get_tax_total(); } // echo '<pre>' . var_export( $woocommerce->cart->get_cart(), true ) . '</pre>'; // echo '<pre>' . var_export( $instance, true ) . '</pre>'; $woocommerce->cart->add_fee('Sales Tax', $fee, true, 'standard'); return $instance; }
<table class="checkout-totals"> <tbody> <tr> <td><b><?php echo $BQ->get_sku_description(); ?> </b></td> <td class="text-right static-width">$<?php echo $BQ->get_sku_price(); ?> </td> </tr> <tr class="border-top"> <td class=""><b>Tax: </b></td> <td class="text-right static-width">$<?php echo $BQ->get_tax_total(); ?> </td> </tr> <tr class=" alert alert-warning"> <td class=""><b>Total: </b></td> <td class="text-right static-width">$<?php echo $BQ->get_total_due(); ?> </td> </tr> </tbody> </table> </div> </div> <form class="payment-form col-lg-6 col-md-6 col-sm-6 col-xs-12" novalidate autocomplete="on" method="POST">