php - Remove WooCommerce subscription interval from cart and checkout pages

I am trying to remove the / month or / year on the cart and checkout page for Woocommerce Subscriptions.

So Instead of $99 / year I only want to show $99

Hoping someone can point me i. the right direction. Thank you

Answer

Solution:

You can try using the following, that will clean everything except the recurring price and totals:

// Items pricing
add_filter( 'woocommerce_subscriptions_product_price_string', 'filter_wc_subscriptions_product_price_string', 10, 3 );
function filter_wc_subscriptions_product_price_string( $price_string, $product, $args ) {
    if ( is_cart() || ( is_checkout() && ! is_wc_endpoint_url() ) ) {
        return $args['price'];
    }
    return $price_string;
}

// Total lines
add_filter( 'woocommerce_subscription_price_string', 'filter_wc_subscription_price_string', 10, 2 );
function filter_wc_subscription_price_string( $subscription_string, $subscription_details ) {
    if ( is_cart() || ( is_checkout() && ! is_wc_endpoint_url() ) ) {
        $recurring_amount = $subscription_details['recurring_amount'];
        
        if( is_numeric( $recurring_amount ) ) {
            return strip_tags( wc_price($recurring_amount) ); // For shipping methods
        }
        else {
            return $recurring_amount;
        }
    }
    return $subscription_string;
}

Based on:

Source