【问题标题】:Woocommerce subscriptions, remove first payment date on cart and checkout pagesWoocommerce 订阅,删除购物车和结帐页面上的首次付款日期
【发布时间】:2020-05-02 15:17:10
【问题描述】:

我想删除(不仅仅是隐藏)购物车和结帐页面上的第一个付款日期,因为这让我的客户非常困惑。 我没有找到覆盖 html 输出的位置和方法。

信息是从 woocommerce 订阅函数 (wcs-cart-functions.php) 添加的,如下所示:

function wcs_add_cart_first_renewal_payment_date( $order_total_html, $cart ) {
    if ( 0 !== $cart->next_payment_date ) {
            $first_renewal_date = date_i18n( wc_date_format(), wcs_date_to_time( get_date_from_gmt( $cart->next_payment_date ) ) );
            // translators: placeholder is a date
            $order_total_html  .= '<div class="first-payment-date"><small>' . sprintf( __( 'First renewal: %s', 'woocommerce-subscriptions' ), $first_renewal_date ) .  '</small></div>';
        }

        return $order_total_html;
    }
    add_filter( 'wcs_cart_totals_order_total_html', 'wcs_add_cart_first_renewal_payment_date', 10, 2 );

出于显而易见的原因,我不想修改核心文件。

我尝试的是在我的主题 CSS 中添加一个 display:none。它有效,但它只是隐藏了信息。

.woocommerce-checkout-review-order-table .first-payment-date {
    display: none;
}

感谢您提供的线索和想法。 弗雷德

【问题讨论】:

    标签: php woocommerce checkout subscription


    【解决方案1】:

    将该函数复制到您的 function.php 文件中并给它一个不同的名称(我添加了“_custom”到我的)。对其进行任何更改。

    然后将以下过滤器添加到function.php中...

    // This removes the default function
    remove_filter( 'wcs_cart_totals_order_total_html', 'wcs_add_cart_first_renewal_payment_date', 10, 2 );
    
    // This runs your version of the function (Note that I'm calling the new '_custom' function) 
    add_filter( 'wcs_cart_totals_order_total_html', 'wcs_add_cart_first_renewal_payment_date_custom', 10, 2 ); 
    

    希望对您有所帮助。

    【讨论】:

    • 谢谢你们。我会试试这个解决方案。
    【解决方案2】:

    好吧,由于似乎没有人回答我的问题,所以我用一个不是最干净的解决方案(在我看来)回答自己,并希望没有隐藏的副作用。 我通过重置 html 输出创建一个新函数来覆盖核心函数:

    /* Hide information of first payment date by override order_total_html output  */
    add_filter( 'wcs_cart_totals_order_total_html', 'hide_first_renewal_payment_date', 100, 2 );
    function hide_first_renewal_payment_date( $order_total_html, $cart ) {
        $order_total_html = '';
        $value            = '<strong>' . $cart->get_total() . '</strong> ';
        // If prices are tax inclusive, show taxes here
        if ( wc_tax_enabled() && $cart->tax_display_cart == 'incl' ) {
            $tax_string_array = array();
    
            if ( get_option( 'woocommerce_tax_total_display' ) == 'itemized' ) {
                foreach ( $cart->get_tax_totals() as $code => $tax ) {
                    $tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
                }
            } else {
                $tax_string_array[] = sprintf( '%s %s', wc_price( $cart->get_taxes_total( true, true ) ), WC()->countries->tax_or_vat() );
            }
    
            if ( ! empty( $tax_string_array ) ) {
                // translators: placeholder is price string, denotes tax included in cart/order total
                $value .= '<small class="includes_tax">' . sprintf( _x( '(Includes %s)', 'includes tax', 'woocommerce-subscriptions' ), implode( ', ', $tax_string_array ) ) . '</small>';
            }
        }
    
        $order_total_html .= $value;
        return $order_total_html;
    }
    

    如果有人能指出更好的解决方案,我会很高兴。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-27
      • 1970-01-01
      • 2018-10-01
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多