Hide “free trial” text from Woocommerce Subscriptions price but keep the Sign-Up Fee

…衆ロ難τιáo~ 提交于 2020-01-05 04:15:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!