Created
November 8, 2015 08:04
-
-
Save vajrasar/3921e6f39c6245dafda1 to your computer and use it in GitHub Desktop.
To add a Size Guide button that opens an image in lightbox based on category (ring or bangle) and if variation size is set -- 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 | |
//To add a Size Guide button that opens an image in lightbox based on category (ring or bangle) and if variation size is set -- WooCommerce | |
//Use lightbox of your choice | |
add_action( 'woocommerce_before_add_to_cart_button', 'vg_sizing_placement', 5 ); | |
function vg_sizing_placement() { | |
global $product, $post; | |
if( is_single() && $product->is_type( 'variable' ) ) { | |
$attributes = $product->get_attributes(); | |
foreach ( $attributes as $attribute ) { | |
if ( $attribute['name'] == 'pa_' . 'size' ) { | |
$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' ); | |
foreach ($product_cats as $key => $value) { | |
$parents[] = $value->parent; | |
} | |
if( in_array( 'rings', $parents ) ) { | |
?> | |
<div id="sizeimg"> | |
<a href="#" data-featherlight="<URL OF RING SIZE IMAGE>">Size Guide</a> | |
</div> | |
<?php | |
} else if( in_array( 'bangles', $parents ) ) { | |
?> | |
<div id="sizeimg"> | |
<a href="#" data-featherlight="<URL OF BANGLE SIZE IMAGE>">Size Guide</a> | |
</div> | |
<?php | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment