【问题标题】:WooCommerce + Xero: Passing through the cart total issueWooCommerce + Xero:通过购物车总问题
【发布时间】:2014-08-18 03:09:48
【问题描述】:

我们有一个网站在运行: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 插件时,它无法收取一次性费用。

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

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    我们刚刚遇到了同样的问题。以下是对插件 (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 ) ) {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多