Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action('widgets_init', 'foxyshop_load_widgets_custom');
- function foxyshop_load_widgets_custom() {
- register_widget('FoxyShop_SingleProduct');
- }
- class FoxyShop_SingleProduct extends WP_Widget {
- //Widget Setup
- function FoxyShop_SingleProduct() {
- $widget_ops = array( 'classname' => 'foxyshop_single-rpduct', 'description' => __('Show a ') . strtolower(FOXYSHOP_PRODUCT_NAME_SINGULAR));
- $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'foxyshop-single-product-widget' );
- $this->WP_Widget( 'foxyshop-single-product-widget', __('FoxyShop ') . FOXYSHOP_PRODUCT_NAME_SINGULAR, $widget_ops, $control_ops );
- }
- //Widget Display
- function widget( $args, $instance ) {
- extract( $args );
- //Our variables from the widget settings
- $title = apply_filters('widget_title', $instance['title'] );
- $productID = $instance['productID'];
- $showMoreDetails = isset( $instance['showMoreDetails'] ) ? $instance['showMoreDetails'] : false;
- $showAddToCart = isset( $instance['showAddToCart'] ) ? $instance['showAddToCart'] : false;
- echo $before_widget;
- if ($title) echo $before_title . $title . $after_title;
- echo '<div class="foxyshop_category_widget">';
- global $product;
- echo '<ul class="foxyshop_featured_product_list">';
- $args = array('post_type' => 'foxyshop_product', "p" => $productID);
- $featuredlist = get_posts($args);
- foreach($featuredlist as $featuredprod) {
- $product = foxyshop_setup_product($featuredprod);
- if ($product['hide_product']) continue;
- $thumbnailSRC = foxyshop_get_main_image("thumbnail");
- echo '<li class="foxyshop_product_box">'."\n";
- echo '<div class="foxyshop_product_image">';
- echo '<a href="' . $product['url'] . '"><img src="' . $thumbnailSRC . '" alt="' . esc_attr($product['name']) . '" class="foxyshop_main_image" /></a>';
- echo "</div>\n";
- echo '<div class="foxyshop_product_info">';
- echo '<h2><a href="' . $product['url'] . '">' . apply_filters('the_title', $product['name']) . '</a></h2>';
- foxyshop_price();
- if ($showMoreDetails) echo '<a href="' . $product['url'] . '" class="foxyshop_button">' . __('More Details') . '</a>';
- if ($showAddToCart) echo '<a href="' . foxyshop_product_link("", true) . '" class="foxyshop_button">' . __('Add To Cart') . '</a>';
- echo "</div>\n";
- echo '<div class="clr"></div>';
- echo "</li>\n";
- }
- echo "</ul><div class=\"clr\"></div>\n";
- echo '</div>';
- echo $after_widget;
- }
- //Update Widget Settings
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- /* Strip tags for title and name to remove HTML (important for text inputs). */
- $instance['title'] = strip_tags( $new_instance['title'] );
- $instance['productID'] = strip_tags( $new_instance['productID'] );
- /* No need to strip tags */
- $instance['showAddToCart'] = $new_instance['showAddToCart'];
- $instance['showMoreDetails'] = $new_instance['showMoreDetails'];
- return $instance;
- }
- //Widget Control Panel
- function form( $instance ) {
- //Defaults
- $defaults = array(
- 'title' => "",
- 'productID' => "",
- 'showAddToCart' => "",
- 'showMoreDetails' => "on",
- );
- $instance = wp_parse_args( (array) $instance, $defaults ); ?>
- <!-- Widget Title: Text Input -->
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:'); ?></label>
- <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:260px;" />
- </p>
- <!-- Select Product -->
- <p>
- <label for="<?php echo $this->get_field_id( 'productID' ); ?>"><?php _e('Product:'); ?></label>
- <select id="<?php echo $this->get_field_id( 'productID' ); ?>" name="<?php echo $this->get_field_name( 'productID' ); ?>" class="widefat" style="width:100%;">
- <option value="">- - Select Product - -</option>
- <?php
- $args = array('post_type' => 'foxyshop_product', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => "name", "order" => "ASC");
- $products = get_posts($args);
- foreach ($products as $theproduct) {
- echo '<option value="' . $theproduct->ID .'"';
- if ($instance['productID'] == $theproduct->ID) echo ' selected="selected"';
- echo '>' . $theproduct->post_title . '</option>';
- }
- ?>
- </select>
- </p>
- <!-- Show Checkboxes for Button Selection -->
- <p>
- <input class="checkbox" type="checkbox" <?php checked( $instance['showAddToCart'], 'on' ); ?> id="<?php echo $this->get_field_id( 'showAddToCart' ); ?>" name="<?php echo $this->get_field_name( 'showAddToCart' ); ?>" />
- <label for="<?php echo $this->get_field_id( 'showAddToCart' ); ?>"><?php _e('Show Add To Cart Button'); ?></label>
- </p>
- <p>
- <input class="checkbox" type="checkbox" <?php checked( $instance['showMoreDetails'], 'on' ); ?> id="<?php echo $this->get_field_id( 'showMoreDetails' ); ?>" name="<?php echo $this->get_field_name( 'showMoreDetails' ); ?>" />
- <label for="<?php echo $this->get_field_id( 'showMoreDetails' ); ?>"><?php _e('Show More Details Button'); ?></label>
- </p>
- <?php
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement