WooCommerce + Xero:通过购物车总问题


WooCommerce + Xero: Passing through the cart total issue

我们有一个网站在运行:http://www.presentu.co.nz

该网站运行Wordpress, WooCommerce和Xero插件。

该网站有一个功能,如果用户购买一个玻璃杯并上传一个标志到该网站,它将通过额外的一次性费用。这是在functions.php文件中添加的:

add_action( 'woocommerce_before_calculate_totals', 'cp_add_custom_price' );
function cp_add_custom_price( $cart_object ) {
global $woocommerce;
foreach ( $cart_object->cart_contents as $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 my logo/i", $cartItemData)) {    
        $excost = 99;
        $woocommerce->cart->add_fee( 'Logo set up 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 up 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 = '' );
    }
}   
}

这可以为多个产品增加一次性费用,因为我找不到现成的解决方案。费用会加到发票上的购物车总额中。

由于某些原因,当它传递到Xero插件时,它没有收取一次性费用。

有没有人有任何经验的Xero插件WooCommerce和能够通过额外的费用?

我们刚刚遇到了同样的问题。以下是对插件(woocommerce-xero.php)的一些编辑,应该可以为您解决这个问题。我的编辑可能不是最有说服力的代码,但对不起。

将第471-483行替换为以下行(只是一些小的编辑):

        //Grab fees as well
        $fees=$order->get_fees();
        foreach($fees as $v)
            $items[]=$v;
        // Add Each item as a line item AND add fees
        foreach( $items as $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 ) ) {