Woocommerce 订阅产品价格字符串

Woocommerce Subscriptions Product Price String

我有一个可以更改订阅详细信息文本的功能。

function wc_subscriptions_custom_price_string( $pricestring ) {
global $product;

$products_to_change = array( 2212 );

if ( in_array( $product->id, $products_to_change ) ) {
    $pricestring = str_replace( 'on the 20th day of every 6th month', 'on the 20th November and 20th May', $pricestring );
}

return $pricestring;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );

这很好用 - 但它不会更改购物车或迷你购物车中的文本 - 仍然显示每 6 个月的第 20 天的默认文本。我如何将其也应用到购物车?

试试这个代码,

function wc_subscriptions_custom_price_string( $pricestring ) {
global $product;

$products_to_change = array( 2212 );

if ( in_array( $product->id, $products_to_change ) ) {
    $newprice = str_replace( 'on the 20th day of every 6th month', 'on the 20th November and 20th May', $pricestring );
}

return $newprice;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string' );

希望一切顺利!!

我认为您需要使用一个函数应用于产品页面(您使用 global $product 的地方),并使用另一个函数应用于购物车。

所以你需要两者:

//* Function for Product Pages
function wc_subscriptions_custom_price_string( $pricestring, $product, $include ) {

    global $product;

    $products_to_change = array( 2212 );

    if ( in_array( $product->id, $products_to_change ) ) {
        $pricestring = str_replace( 'on the 20th day of every 6th month', 'on the 20th November and 20th May', $pricestring );
    }

    return $pricestring;

}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );

//* Function for Cart
function wc_subscriptions_custom_price_string_cart( $pricestring ) {

    $pricestring = str_replace( 'on the 20th day of every 6th month', 'on the 20th November and 20th May', $pricestring );

    return $pricestring;

}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string_cart' );
add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string_cart' );