custom-add-to-cart-button.php
· 853 B · PHP
Eredeti
/* START custom add to cart button on home */
function custom_add_to_cart_button_with_icon() {
// Remove the default add to cart button
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
// Add the new custom button
add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart_with_icon', 10);
}
function woocommerce_template_loop_add_to_cart_with_icon() {
global $product;
echo sprintf('<a href="%s" class="button add_to_cart_button" style="display:inline-block; background-image:url(\'https://staging.qrh.app/wp-content/uploads/2024/03/XL-2.png\'); width: 48px; height: 48px; background-size: cover;"></a>', esc_url($product->add_to_cart_url()));
}
add_action('init', 'custom_add_to_cart_button_with_icon');
/* END custom add to cart button on home */
1 | /* START custom add to cart button on home */ |
2 | function custom_add_to_cart_button_with_icon() { |
3 | // Remove the default add to cart button |
4 | remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10); |
5 | |
6 | // Add the new custom button |
7 | add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart_with_icon', 10); |
8 | } |
9 | |
10 | function woocommerce_template_loop_add_to_cart_with_icon() { |
11 | global $product; |
12 | echo sprintf('<a href="%s" class="button add_to_cart_button" style="display:inline-block; background-image:url(\'https://staging.qrh.app/wp-content/uploads/2024/03/XL-2.png\'); width: 48px; height: 48px; background-size: cover;"></a>', esc_url($product->add_to_cart_url())); |
13 | } |
14 | |
15 | add_action('init', 'custom_add_to_cart_button_with_icon'); |
16 | |
17 | |
18 | /* END custom add to cart button on home */ |
19 |