Created
May 12, 2020 06:06
-
-
Save wplit/356f4bc513daba290c0cffe5dd13b3ce to your computer and use it in GitHub Desktop.
single product image flip
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
| // Remove zoom and slider from single product | |
| add_action("after_setup_theme", "lit_remove_woo_theme_support"); | |
| function lit_remove_woo_theme_support() { | |
| remove_theme_support( 'wc-product-gallery-zoom' ); | |
| remove_theme_support( 'wc-product-gallery-slider' ); | |
| } | |
| // Remove product thumbnails | |
| remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 ); | |
| // Add secondary image below first image on single product page | |
| add_action( 'wp_head', 'lit_woo_single_image_flipping' ); | |
| function lit_woo_single_image_flipping() { | |
| // check if WooCommerce active | |
| if (!class_exists( 'WooCommerce' ) ) { | |
| return; | |
| } | |
| /* Abort if we're not on a single product */ | |
| if ( !is_product() ) { | |
| return; | |
| } | |
| /* Add Second Thumbnail below first thumbnail */ | |
| add_action( 'woocommerce_product_thumbnails', 'lit_second_single_product_thumbnail' ); | |
| } | |
| //* Function to get second product thumbnail from product gallery | |
| function lit_second_single_product_thumbnail() { | |
| global $product; | |
| $attachment_ids = $product->get_gallery_image_ids(); | |
| if ( $attachment_ids ) { | |
| $attachment_ids = array_values( $attachment_ids ); | |
| $secondary_image_id = $attachment_ids['0']; | |
| $secondary_image_alt = get_post_meta( $secondary_image_id, '_wp_attachment_image_alt', true ); | |
| $secondary_image_title = get_the_title($secondary_image_id); | |
| echo wp_get_attachment_image( | |
| $secondary_image_id, | |
| 'shop_catalog', | |
| '', | |
| array( | |
| 'class' => 'secondary-image attachment-woocommerce_thumbnail', | |
| 'alt' => $secondary_image_alt, | |
| 'title' => $secondary_image_title | |
| ) | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment