dpzbzp8728 2017-09-05 10:31
浏览 28
已采纳

根据收费有条件地定制WooCommerce购物车总产量

I try to do a quite simple thing but for me i don´t get it to work.

This is from the wc-cart-functions.php

        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 );
}

The $value should be different if any $fee is applied. But I only get 0.00 € Value from $fee Variable if I check for.

Could someone please help me with simply apply the Value of the FEE in a Variable and check in a simple if clause like:

if fee is applied ---> 1
else ---> 2

How can I do it?

  • 写回答

1条回答 默认 最新

  • duanjiao4763 2017-09-05 18:52
    关注

    As you can see you can use the woocommerce_cart_totals_order_total_html filter hook located in that wc-cart-functions.php core code, to alter the output of grand cart total:

    add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_cart_totals_order_total_html', 10, 1 );
    function custom_cart_totals_order_total_html( $value ) {
        // Get the fee cart amount
        $fees_total = WC()->cart->fee_total;
    
        // HERE is the condition
        if( ! empty($fees_total) && $fees_total != 0 ){
            // Change/customize HERE $value (just for test)
            $value .= " <small>($fees_total)<small>";
        }
    
        // Always return $value
        return $value;
    }
    

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    This code is tested and works.

    Never overide core files, as this is something prohibited, dangerous and not convenient for many reasons

    You will need to customize the code in the condition for $value

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度