skip to Main Content

I would like to remove (not just hide) the first payment date on the cart and checkout pages because it’s very confusing for my client.
I don’t find where and how to override the html output.

The information is added from a woocommerce subscription function (wcs-cart-functions.php) as following:

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

For obvious reasons, I don’t want to modify the core files.

What I’ve tried is to add a display:none in my theme CSS. It works but it just hides the information.

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

Thank you for your clues and ideas.
Fred

2

Answers


  1. Chosen as BEST ANSWER

    Well, as no one seems to have reached my question, I answer to myself with not a cleanest solution (in my opinion) and hoping there is no hidden side effect. I override the core function by creating a new one by reseting the html output:

    /* 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;
    }
    

    I'd be glad if someone could point me to a better solution.


  2. Copy that function to your function.php file and give it a different name (I added ‘_custom’ to mine). Make whatever changes you want to it.

    Then add the following filters into 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 ); 
    

    Hope that helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search