【问题标题】:How to show Product Price + Shipping VAT in "Total" Merged如何在“总计”合并中显示产品价格 + 运费增值税
【发布时间】:2018-09-02 12:43:26
【问题描述】:

我有一个不知道如何解决自己的小问题。我已经在我的商店里设置了单独显示价格和运费,但总的来说显示我的价格很差。

例如,我的产品成本为 24.99 欧元 + 运费:3,95 欧元 = 28.94 欧元,但在购物车页面的计算中计算的是:24.99 欧元 + 3.95 欧元 - 0.26 欧元,这是怎么回事。

我发现总价是通过这个函数计算出来的:

<td data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>"><?php wc_cart_totals_order_total_html(); ?></td>

这是控制该部分的功能: 来自模板中的 cart-totals.php,下面是来自 wc-cart-functions.php

的函数
function wc_cart_totals_order_total_html() {
$value = '<strong>' . WC()->cart->get_total() . '</strong> ';

// If prices are tax inclusive, show taxes here.
if ( wc_tax_enabled() && WC()->cart->display_prices_including_tax() ) {
    $tax_string_array = array();
    $cart_tax_totals  = WC()->cart->get_tax_totals();

    if ( get_option( 'woocommerce_tax_total_display' ) == 'itemized' ) {
        foreach ( $cart_tax_totals as $code => $tax ) {
            $tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
        }
    } elseif ( ! empty( $cart_tax_totals ) ) {
        $tax_string_array[] = sprintf( '%s %s', wc_price( WC()->cart->get_taxes_total( true, true ) ), WC()->countries->tax_or_vat() );
    }

    if ( ! empty( $tax_string_array ) ) {
        $taxable_address = WC()->customer->get_taxable_address();
        $estimated_text  = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping()
            ? sprintf( ' ' . __( 'estimated for %s', 'woocommerce' ), WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ] )
            : '';
        $value .= '<small class="includes_tax">' . sprintf( __( '(includes %s)', 'woocommerce' ), implode( ', ', $tax_string_array ) . $estimated_text ) . '</small>';
    }
}

echo apply_filters( 'woocommerce_cart_totals_order_total_html', $value );
}

所以我的问题是如何以总价添加 1.63E,这样才能得到正确的价格。谢谢

编辑:发现与我的here 相同的问题,但答案似乎没有改变。

【问题讨论】:

  • 仅此一段代码可能还不够。可以将此问题发布到 WooCommerce,也可以在他们的论坛上发布,如果他们有的话。
  • 我也在那里打开过,但也在这里问,因为有大量的 Woocommerce 开发人员,所以可能会得到一些答案或提示。

标签: wordpress woocommerce


【解决方案1】:

首先,感谢您的帖子,我几乎认为我是唯一有这种需求的人。

到目前为止,这适用于我的商店。我确信我的代码对于不同的商店设置不是很通用。也许有人可以制作一个更通用的可用版本。

编辑:我添加了一张显示两种费率的图片。 Image of the result 我发现了计算运费税的一个小错误,现在更正。

/**
 * Change Tax Amount including Shipping Taxes
 * Referencing to wc-cart-functions.php starting from Line 296
 *
*/
add_filter( 'woocommerce_cart_totals_order_total_html', 'woo_rename_tax_inc_cart', 10, 1 );
function woo_rename_tax_inc_cart( $value ) {
    /* Get all infos needed */
    $shipping_total = WC()->cart->shipping_total;
    $taxes = WC()->cart->get_taxes_total( true, true );
    $taxrate = 7.7;
    $newtaxes = ($shipping_total/(100+$taxrate)*$taxrate) + $taxes; // Shipping is 100% + taxrate %, so we deduct both percentages.

    /* Check if Shipment total is active */
    if ( ! empty($shipping_total) && $shipping_total != 0 ) { 
        if ( ! empty( $value ) ) {
            // Show Price /wc-cart-functions.php Line 297
            $value = '<strong>' . WC()->cart->get_total() . '</strong> ';
            $value .= '<small class="includes_tax">' . '(inkl. ' . wc_price( $newtaxes ) . ' MWST)' . '</small>';
        }
    }

    // Attach Tax Info to Price (single line)
    $value = str_ireplace( 'Tax', 'GST', $value );

    return $value;
}

【讨论】:

    猜你喜欢
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    • 2013-10-23
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 2015-10-26
    相关资源
    最近更新 更多