问题
The first part of the question (Hide the “free trial” text from Woocommerce Subscriptions price) was answered in this awesome post:
Hide the "free trial" text from Woocommerce Subscriptions price
However, it removed the "and a xx sign-up fee". Is there any way to keep the sign up fee text after removing the free trial text?
回答1:
Updated - Try the following:
add_filter( 'woocommerce_subscriptions_product_price_string', 'subscriptions_custom_price_string', 20, 3 );
function subscriptions_custom_price_string( $price_string, $product, $args ) {
// Get the trial length to check if it's enabled
$trial_length = get_post_meta( $product->get_id(), '_subscription_trial_length', true );
$speriod = get_post_meta( $product->get_id(), '_subscription_period', true );
$sfee = get_post_meta( $product->get_id(), '_subscription_sign_up_fee', true );
$sfee = wc_price($sfee);
$sign_up_fee = isset($args['sign_up_fee']) ? __(" and a $sfee sign-up fee", "woocommerce") : '';
if( $trial_length > 0 )
$price_string = $args['price'] . ' / ' . $speriod . $sign_up_fee;
return $price_string;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
来源:https://stackoverflow.com/questions/50751569/hide-free-trial-text-from-woocommerce-subscriptions-price-but-keep-the-sign-up