我需要一个更好的方式来做到这一点。
目前,我已经直接添加代码类-WC-订阅-product.php文件内的get_price_string功能,所以当一个免费试用的设置,我可以改变文本被添加到字符串的价格。
这当然是远远不够完善。
因此,没有人知道我需要添加到在主题文件夹中的functions.php文件,以便能够做同样的事情是什么挂钩?
这里是我的网站非常简单的版本。我需要有它“每个季节”,而不是“每3个月”之称。最简单的方法是创建一个插件:
<?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' );
OK老问题,但我需要最近做到这一点。我不想依靠字符串替换,所以这是我做到了(可以调整,以适应您的需求 - 他们关键是看在$product
这是提供给你的属性):
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 );
}
在/public_html/wp-content/plugins/woocommerce-subscriptions/includes/class-wc-subscriptions-product.php
查找get_price_string(...)
在此调整布尔值:
$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,
)
);