Skip to content

Instantly share code, notes, and snippets.

@vajrasar
Created November 8, 2015 08:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vajrasar/3921e6f39c6245dafda1 to your computer and use it in GitHub Desktop.
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
<?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