问题
I am looking for a filter/action hook (or any other way) to change image URL that is displayed on cart page as a thumbnail.
Example image: http://jamescollings.co.uk/wp-content/uploads/2014/12/cart-donation-form.png
I found that it is retrieved via $_product->get_image()
method, but I could not find anything similar to $_product->set_image()
.
回答1:
I have found the answer:
The hook is woocommerce_cart_item_thumbnail
.
So in your functions.php
add
function custom_new_product_image($a) {
$class = 'attachment-shop_thumbnail wp-post-image'; // Default cart thumbnail class.
$src = [PATH_TO_YOUR_NEW_IMAGE];
// Construct your img tag.
$a = '<img';
$a .= ' src="' . $src . '"';
$a .= ' class="' . $class . '"';
$a .= ' />';
// Output.
return $a;
}
add_filter( 'woocommerce_cart_item_thumbnail', 'custom_new_product_image' );
and your thumbnails will be replaced (more processing needed if you want to change each thumbnail individually).
来源:https://stackoverflow.com/questions/32876133/woocommerce-change-product-image-permalink-with-filter-action-hook