Как добавить собственный html-класс в цикл WooCommerce и добавить ссылку в корзину?Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Как добавить собственный html-класс в цикл WooCommerce и добавить ссылку в корзину?

Сообщение 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/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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»