function custom_external_add_to_cart_button($button, $product) {
// Check if the product is of type 'external'
if ($product->is_type('external')) {
// Direct URL to the Amazon icon image
$icon_url = 'https://mejormovil.es/wp-content/themes/woodmart/images/amazon-icon.png';
// Define the button text
$button_text = 'See Prices';
// Create the button HTML with the Amazon icon and new text
$button = sprintf(
'<a href="%s" class="button product_type_external add-to-cart-loop customize-unpreviewable" data-product_id="%s" aria-label="%s" rel="nofollow">
<img src="%s" style="width: 20px; height: auto; margin-right: 5px; vertical-align: middle;" alt="Amazon Icon"/> %s
</a>',
esc_url($product->add_to_cart_url()), // URL for the product
esc_attr($product->get_id()), // Product ID
esc_attr($product->add_to_cart_description()), // ARIA label
esc_url($icon_url), // Amazon icon URL
esc_html($button_text) // Button text
);
}
// Return the modified button HTML
return $button;
}
// Apply the filter to modify the external product button
add_filter('woocommerce_loop_add_to_cart_link', 'custom_external_add_to_cart_button', 10, 2);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter