Skip to content

Instantly share code, notes, and snippets.

@woogist
Created June 17, 2014 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woogist/61aa26885ba8495ddef6 to your computer and use it in GitHub Desktop.
Save woogist/61aa26885ba8495ddef6 to your computer and use it in GitHub Desktop.
add slider to the shop page
//load the slides on the shop page:
add_action( 'woocommerce_before_shop_loop', 'shop_woo_featured_slider_loader' );
function shop_woo_featured_slider_loader () {
if( is_shop() ){
$settings = woo_get_dynamic_values( array( 'featured' => 'true' ) );
get_template_part( 'includes/featured', 'slider' );
}
} // End woo_featured_slider_loader()
//load the shop javscript :
add_action( 'woothemes_add_javascript' , 'shop_woo_load_featured_slider_js' );
function shop_woo_load_featured_slider_js() {
if( is_shop() ){
//Slider settings
$settings = array(
'featured_speed' => '7',
'featured_hover' => 'true',
'featured_action' => 'true',
'featured_touchswipe' => 'true',
'featured_animation_speed' => '0.6',
'featured_pagination' => 'false',
'featured_nextprev' => 'true',
'featured_animation' => 'fade'
);
$settings = woo_get_dynamic_values( $settings );
if ( $settings['featured_speed'] == '0' ) { $slideshow = 'false'; } else { $slideshow = 'true'; }
if ( 'true' == $settings['featured_touchswipe'] ) { $touchSwipe = 'true'; } else { $touchSwipe = 'false'; }
if ( 'true' == $settings['featured_hover'] ) { $pauseOnHover = 'true'; } else { $pauseOnHover = 'false'; }
if ( 'true' == $settings['featured_action'] ) { $pauseOnAction = 'true'; } else { $pauseOnAction = 'false'; }
if ( ! in_array( $settings['featured_animation'], array( 'fade', 'slide' ) ) ) { $settings['featured_animation'] = 'fade'; }
$slideshowSpeed = (int) $settings['featured_speed'] * 1000; // milliseconds
$nextprev = $settings['featured_nextprev'];
$manualControls = '';
if ( $settings['featured_pagination'] == 'true' ) {
$pagination = 'true';
} else {
$pagination = 'false';
}
$data = array(
'animation' => $settings['featured_animation'],
'controlsContainer' => '.controls-container',
'smoothHeight' => 'true',
'directionNav' => $nextprev,
'controlNav' => $pagination,
'manualControls' => $manualControls,
'slideshow' => $slideshow,
'pauseOnHover' => $pauseOnHover,
'slideshowSpeed' => $slideshowSpeed,
'touch' => $touchSwipe,
'pauseOnHover' => $pauseOnHover,
'pauseOnAction' => $pauseOnAction
);
wp_localize_script( 'featured-slider', 'woo_localized_data', $data);
wp_enqueue_script( 'featured-slider' );
}
} // End woo_load_featured_slider_js()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment