Woocommerce订阅产品价格字符串

时间:2018-01-08 07:44:32

标签: wordpress woocommerce woocommerce-subscriptions

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

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天的默认文字。我如何将其应用于购物车?

2 个答案:

答案 0 :(得分:1)

试试这段代码,



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' );




希望它的工作!!

答案 1 :(得分:1)

我相信你需要使用一个功能来应用于产品页面(你使用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' );