0

При цене товара = 0, нужно поменять текст кнопки "Добавить в корзину" на "Запросить стоимость".

Написал такой код с условиями. Но он крашит ВордПресс.

function my_theme_cart_button_text() {
    return 'Запросить стоимость';
    }


function nulled_price_call ($product) {
    if ($product -> get_price() == 0) {
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'my_theme_cart_button_text' );
}
}

nulled_price_call();

Я новичок в php, буду рад вашей помощи

1 ответ 1

1

вы можете это сделать вот так

add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text', 10, 2 );

function woocommerce_custom_single_add_to_cart_text( $btn_text, $product ) {
    return $product->get_price() ? $btn_text : __( 'Запросить стоимость', 'woocommerce' );
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.