Мы хотим добавить класс CSS к некоторым конкретным кнопкам, добавив к существующему PHP.
Это наш существующий PHP, который меняет текст кнопки. [взято из другого места в StackOverFlow]
/**
* @snippet Read more > Out of stock @ WooCommerce Shop
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 5
* @community https://businessbloomer.com/club/
* See: https://www.businessbloomer.com/woocomm ... tock-shop/
*/
add_filter( 'woocommerce_product_add_to_cart_text', 'bbloomer_archive_custom_cart_button_text' );
function bbloomer_archive_custom_cart_button_text( $text ) {
global $product;
if ( $product && ! $product->is_purchasable() ) { /* original example was: ! $product->is_in_stock() */
return 'Active';
}
return $text;
}
Это HTML-код после запуска вышеуказанного PHP.
£0.00
for 2 years
Active
Out of stock @ WooCommerce Shop
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 5
* @community https://businessbloomer.com/club/
* See: https://www.businessbloomer.com/woocomm ... tock-shop/
*/
add_filter( 'woocommerce_product_add_to_cart_text', 'bbloomer_archive_custom_cart_button_text' );
function bbloomer_archive_custom_cart_button_text( $text ) {
global $product;
if ( $product && ! $product->is_purchasable() ) { /* original example was: ! $product->is_in_stock() */
return 'Active';
}
return $text;
}
/* Also add a class so that custom css can grey-out the button */
add_filter( 'woocommerce_loop_add_to_cart_link', 'filter_loop_add_to_cart_link', 10, 2 );
function filter_loop_add_to_cart_link( $link, $product ) {
// Check if the product is part of an active subscription for the current user
// if ( wcs_user_has_subscription( get_current_user_id(), $product->get_id(), 'active' ) ) { replaced by line below for (attempted) commonality with function above
if ( $product && ! $product->is_purchasable() ) {
$link = str_replace('class="button', 'class="button ActiveSubscription', $link);
}
return $link;
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... -cart-link
Как добавить собственный html-класс в цикл WooCommerce и добавить ссылку в корзину? ⇐ Php
Кемеровские программисты php общаются здесь
1732627768
Anonymous
Мы хотим добавить класс CSS к некоторым конкретным кнопкам, добавив к существующему PHP.
Это наш существующий PHP, который меняет текст кнопки. [взято из другого места в StackOverFlow]
/**
* @snippet Read more > Out of stock @ WooCommerce Shop
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 5
* @community https://businessbloomer.com/club/
* See: https://www.businessbloomer.com/woocommerce-rename-read-more-out-of-stock-shop/
*/
add_filter( 'woocommerce_product_add_to_cart_text', 'bbloomer_archive_custom_cart_button_text' );
function bbloomer_archive_custom_cart_button_text( $text ) {
global $product;
if ( $product && ! $product->is_purchasable() ) { /* original example was: ! $product->is_in_stock() */
return 'Active';
}
return $text;
}
Это HTML-код после запуска вышеуказанного PHP.
£0.00
for 2 years
[url=.../membership/arts-events-marketing-subscription-copy/]Active[/url]
Out of stock @ WooCommerce Shop
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 5
* @community https://businessbloomer.com/club/
* See: https://www.businessbloomer.com/woocommerce-rename-read-more-out-of-stock-shop/
*/
add_filter( 'woocommerce_product_add_to_cart_text', 'bbloomer_archive_custom_cart_button_text' );
function bbloomer_archive_custom_cart_button_text( $text ) {
global $product;
if ( $product && ! $product->is_purchasable() ) { /* original example was: ! $product->is_in_stock() */
return 'Active';
}
return $text;
}
/* Also add a class so that custom css can grey-out the button */
add_filter( 'woocommerce_loop_add_to_cart_link', 'filter_loop_add_to_cart_link', 10, 2 );
function filter_loop_add_to_cart_link( $link, $product ) {
// Check if the product is part of an active subscription for the current user
// if ( wcs_user_has_subscription( get_current_user_id(), $product->get_id(), 'active' ) ) { replaced by line below for (attempted) commonality with function above
if ( $product && ! $product->is_purchasable() ) {
$link = str_replace('class="button', 'class="button ActiveSubscription', $link);
}
return $link;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79224878/how-add-a-custom-html-class-to-woocommerce-loop-add-to-cart-link[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия