Created
March 5, 2015 11:54
-
-
Save mkhairul/8ee5842bcd189125d4be to your computer and use it in GitHub Desktop.
Replace placeholder images with attribute values (woocommerce)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('woocommerce_cart_item_thumbnail', 'get_attr_image', 10, 3); | |
function get_attr_image($image, $item, $item_key) | |
{ | |
$img_url = array_shift( wc_get_product_terms( $item['product_id'], 'pa_image', array( 'fields' => 'names' ) ) ); | |
if($img_url) | |
{ | |
$dom = new DOMDocument(); | |
$dom->loadHTML($image); | |
$node = $dom->getElementsByTagName('img'); | |
$node->item(0)->setAttribute('src', $img_url); | |
$image = $node->item(0)->ownerDocument->saveHTML($node->item(0)); | |
} | |
return $image; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment