How do I change the price string in WooCommerce subscriptions

前端 未结 3 742
[愿得一人]
[愿得一人] 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 );
    }
    
    0 讨论(0)
  • 2021-01-16 10:38

    Here is a VERY simple version for my site. I needed to have it say "per season" instead of "every 3 months". The simplest way was to create a plugin:

    <?php
    /**
     * Plugin Name: My Subscription Price Text
     * Description: Make it say "Every Season" instead of "Every 3 Months"
     * Author: green coder
     * Author URI: 
     * Version: 1.0
     * License: GPL v2
     */
    function my_subs_price_string( $pricestring ) {
    
        $newprice = str_replace( 'every 3 months', 'per season', $pricestring );
    return $newprice;
    
    }
    add_filter( 'woocommerce_subscriptions_product_price_string', 'my_subs_price_string' );
    add_filter( 'woocommerce_subscription_price_string', 'my_subs_price_string' );
    
    0 讨论(0)
  • 2021-01-16 10:40

    In /public_html/wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscriptions-product.php

    Find get_price_string(...)

    Adjust the Boolean values here:

    $include = wp_parse_args( $include, array(
            'tax_calculation'     => get_option( 'woocommerce_tax_display_shop' ),
            'subscription_price'  => true,
            'subscription_period' => true,
            'subscription_length' => true,
            'sign_up_fee'         => true,
            'trial_length'        => true,
        )
    );
    
    0 讨论(0)
提交回复
热议问题