php - WooCommerce + Xero: Passing through the cart total issue -
we have site running at: http://www.presentu.co.nz
the site running wordpress, woocommerce , xero plugin.
the site has feature if user buys glass , uploads logo site, passes through 1 off fee. added in functions.php file as:
add_action( 'woocommerce_before_calculate_totals', 'cp_add_custom_price' ); function cp_add_custom_price( $cart_object ) { global $woocommerce; foreach ( $cart_object->cart_contents $key => $value ) { //$proid = $value['product_id']; //$variantid = $value['variation_id']; //$price = $value['data']->price; $cartitemdata = $woocommerce->cart->get_item_data($value); // menu covers add logo $99 fee if (preg_match("/upload logo/i", $cartitemdata)) { $excost = 99; $woocommerce->cart->add_fee( 'logo set fee', $excost, $taxable = true, $tax_class = '' ); } // glassware add logo $35 fee if (preg_match("/yes, add logo/i", $cartitemdata)) { $excost = 35; $woocommerce->cart->add_fee( 'logo set fee', $excost, $taxable = true, $tax_class = '' ); } // creative print: basic if (preg_match("/standard design/i", $cartitemdata)) { $excost = 60; $woocommerce->cart->add_fee( 'creative print design fee', $excost, $taxable = true, $tax_class = '' ); } // creative print: complex if (preg_match("/creative design/i", $cartitemdata)) { $excost = 110; $woocommerce->cart->add_fee( 'creative print design fee', $excost, $taxable = true, $tax_class = '' ); } } }
this works adding one-off fees multiple products, couldn't find solution off shelf. fee added cart total on invoice.
for reason when passes through xero plugin, fails pick one-off fee.
has had experience xero plugin woocommerce , being able pass through fees?
we struck same issue. here few edits plugin (woocommerce-xero.php) should fix issue you. edits not eloquent code though sorry.
replace lines 471-483 following (just small edits).
//grab fees $fees=$order->get_fees(); foreach($fees $v) $items[]=$v; // add each item line item , add fees foreach( $items $key => $value ) { if($value['type']=="fee") $value['qty']=1; else $product = $order->get_product_from_item( $value ); $replace_pattern = array('“', '”'); $item_description = str_replace($replace_pattern, '""', $value['name']); $xml .= '<lineitem>'; $xml .= '<description>' . htmlspecialchars( $item_description ) .'</description>'; $xml .= '<accountcode>' . $this->sales_account . '</accountcode>'; $xml .= '<quantity>' . $value['qty'] . '</quantity>'; if ( ($value['type']!="fee") && ( 'on' == $this->send_inventory ) && ( '' != $product->sku ) ) {
Comments
Post a Comment