Skip to content

Instantly share code, notes, and snippets.

@marulitua
Last active September 15, 2018 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marulitua/5d2e68e7341c83e0ba2d69edcde41e37 to your computer and use it in GitHub Desktop.
Save marulitua/5d2e68e7341c83e0ba2d69edcde41e37 to your computer and use it in GitHub Desktop.
woocomerce wl
// wp-content/themes/shop-isle-child/functions.php
// add class 'tinvwl-product-in-list' custom css class
add_action('woocommerce_after_shop_loop_item', 'add_a_custom_button', 11 );
function add_a_custom_button() {
global $product;
$wlButton = do_shortcode("[ti_wishlists_addtowishlist product_id=".$product->id."]");
$dom = new DOMDocument;
$dom->loadHTML($wlButton);
$dataTinvWlList = '';
$dataTinvWlProduct = '';
foreach ($dom->getElementsByTagName('a') as $node) {
foreach ($node->attributes as $t) {
if ($t->nodeName == 'data-tinv-wl-list') {
$dataTinvWlList = $t->nodeValue;
}
if ($t->nodeName == 'data-tinv-wl-product') {
$dataTinvWlProduct = $t->nodeValue;
}
}
}
echo '<a class="tinvwl_add_to_wishlist_button button tinvwl-position-after" data-tinv-wl-list="' . $dataTinvWlList . '" data-tinv-wl-product="' . $dataTinvWlProduct . '" data-tinv-wl-productvariation="" data-tinv-wl-producttype="variable" data-tinv-wl-action="addto" rel="nofollow"><span class="tinvwl_add_to_wishlist-text">Add to Wishlist</span></a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment