Skip to content

Instantly share code, notes, and snippets.

@alexmoise
Last active December 18, 2017 18:01
Show Gist options
  • Save alexmoise/0056c5055c501e343fa22527faf66a71 to your computer and use it in GitHub Desktop.
Save alexmoise/0056c5055c501e343fa22527faf66a71 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Noesa DEV environment changes
* Plugin URI: https://gist.github.com/alexmoise/0056c5055c501e343fa22527faf66a71
* GitHub Plugin URI: https://gist.github.com/alexmoise/0056c5055c501e343fa22527faf66a71
* Description: A custom plugin to preserve custom changes against updates, for noesa.com dev environment
* Version: 1.0.0
* Author: Alex Moise
* Author URI: https://moise.pro
*/
// 01. show first product gallery image as product image in single product page
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'noesa_product_image_new');
function noesa_product_image_new($post_id) {
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
if ( $attachment_ids ) {
$attachment_id = $attachment_ids[0];
$classes = array();
$image_link = wp_get_attachment_url( $attachment_id );
if ( $image_link ) {
$image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_thumbnail_size', 'shop_thumbnail' ) );
$image_class = esc_attr( implode( ' ', $classes ) );
$image_title = esc_attr( get_the_title( $attachment_id ) );
}
}
$content = '<a href="' . $image_link . '" itemprop="image" class="woocommerce-main-image zoom" title="' . $image_title . '" data-rel="prettyPhoto">' . $image . '</a>';
return $content;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment