0

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

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

4

2 回答 2

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

希望它的工作!

于 2018-01-08T08:22:36.100 回答
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' );
于 2018-04-05T18:29:38.087 回答