How do I change the price string in WooCommerce subscriptions

前端 未结 3 772
[愿得一人]
[愿得一人] 2021-01-16 09:56

I need a better way to do this.

Currently, I have added code directly to the get_price_string function within class-wc-subscriptions-product.php file, so when a free

3条回答
  •  耶瑟儿~
    2021-01-16 10:21

    OK old question but I needed to do this recently. I didn't want to rely on string replacement so this is how I did it (can be adapted to suit your needs - they key is to look at the attributes in $product which are available to you):

    add_filter( 'woocommerce_subscriptions_product_price_string', 'my_subs_price_string', 10, 3 );
    
    function my_subs_price_string( $subscription_string, $product, $include ) {
    
        /****
        var_dump($product); Various variables are available to us
        ****/
    
        return 'An initial easy payment of ' . wc_price( $product->subscription_sign_up_fee ) . 
            ', a ' . $product->subscription_trial_length . ' ' . $product->subscription_trial_period . 
            ' trial of the product, then an outright purchase of ' . wc_price( $product->subscription_price );
    }
    

提交回复
热议问题