Last active
May 7, 2020 18:41
-
-
Save bekarice/57dbb20278683319d3e1 to your computer and use it in GitHub Desktop.
Make the product box images in WordPress Simple PayPal Shopping Cart lightbox previews instead
This file contains 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
/** | |
* Let's make the product box images in WPSPSC lightbox previews instead | |
* | |
* The plugin is here: https://wordpress.org/plugins/wordpress-simple-paypal-shopping-cart | |
* Using this lightbox plugin: https://wordpress.org/plugins/responsive-lightbox/ | |
*/ | |
function make_wpspsc_thumbs_lightbox_previews( $thumbnail, $atts ) { | |
// Code Credit: http://stackoverflow.com/questions/19323324/how-to-get-image-src-attribute-value-from-php-string | |
$doc = new DOMDocument(); | |
// Let's make sure we don't execute this code on the wrong elements & blow up the site | |
if ( ! is_object( $doc ) ) { | |
return $thumbnail; | |
} | |
libxml_use_internal_errors(true); | |
$doc->loadHTML( $thumbnail ); | |
$xpath = new DOMXPath($doc); | |
$imgs = $xpath->query("//img"); | |
for ($i=0; $i < $imgs->length; $i++) { | |
$img = $imgs->item($i); | |
$src = $img->getAttribute("src"); | |
} | |
// Now let's use the image src we just got & rel="lightbox" because that's what Responsive Lightbox from dFactory uses | |
$new_thumbnail = '<a href="'.$src.'" rel="lightbox">'.$thumbnail.'</a>'; | |
return $new_thumbnail; | |
} | |
add_filter( 'wspsc_product_box_thumbnail_code', 'make_wpspsc_thumbs_lightbox_previews' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment