Строка цены продукта для подписок Woocommerce

У меня есть функция, которая может изменять текст деталей подписки.

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

Это работает хорошо, но не меняет текст в тележке или мини-тележке, в которой по-прежнему отображается текст по умолчанию 20-го числа каждого 6-го месяца. Как применить это к корзине?


person Paul VI    schedule 08.01.2018    source источник


Ответы (2)


Попробуйте этот код,

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

Надеюсь, что это работает !!

person Priyanka Modi    schedule 08.01.2018

Я считаю, что вам нужно использовать одну функцию для применения к страницам продуктов (где вы используете 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' );
person Alex Mustin    schedule 05.04.2018