public function list_post_html($args, $instance, WP_Query $query) { $post_type = $this->get_post_type_from_instance($instance); $post_types = array(); foreach ($post_type as $fvdata) { $ptvalue = isset($fvdata['value']) ? $fvdata['value'] : ''; if (!empty($ptvalue)) { $post_types[] = $ptvalue; } } $full_width_post = hocwp_get_value_by_key($instance, 'full_width_post', $this->args['full_width_post']); $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail')); $thumbnail_size = isset($instance['thumbnail_size']) ? $instance['thumbnail_size'] : $this->args['thumbnail_size']; $thumbnail_size = hocwp_sanitize_size($thumbnail_size); $excerpt_length = isset($instance['excerpt_length']) ? $instance['excerpt_length'] : $this->args['excerpt_length']; $title_length = hocwp_get_value_by_key($instance, 'title_length', hocwp_get_value_by_key($this->args, 'title_length')); $list_class = 'list-unstyled'; foreach ($post_types as $ptvalue) { hocwp_add_string_with_space_before($list_class, 'list-' . $ptvalue . 's'); } $list_class = apply_filters('hocwp_widget_post_list_class', $list_class, $args, $instance, $this); $widget_html = '<ul class="' . $list_class . '">'; $loop_html = apply_filters('hocwp_widget_post_loop_html', '', $args, $instance, $this); if (empty($loop_html)) { $count = 0; ob_start(); while ($query->have_posts()) { $query->the_post(); $post_id = get_the_ID(); $post = get_post($post_id); $class = 'a-widget-post'; $full_width = false; if ('all' == $full_width_post) { $full_width = true; } elseif ('first' == $full_width_post && 0 == $count) { $full_width = true; } elseif ('last' == $full_width_post && $count == $query->post_count) { $full_width = true; } elseif ('first_last' == $full_width_post && (0 == $count || $count == $query->post_count)) { $full_width = true; } elseif ('odd' == $full_width_post && $count % 2 != 0) { $full_width = true; } elseif ('even' == $full_width_post && $count % 2 == 0) { $full_width = true; } if ($full_width) { hocwp_add_string_with_space_before($class, 'full-width'); } if ($hide_thumbnail) { hocwp_add_string_with_space_before($class, 'hide-thumbnail'); } if (hocwp_is_positive_number($excerpt_length)) { hocwp_add_string_with_space_before($class, 'show-excerpt'); } else { hocwp_add_string_with_space_before($class, 'hide-excerpt'); } ?> <li <?php post_class($class); ?> > <?php do_action('hocwp_widget_post_before_post', $args, $instance, $this); if (!(bool) $hide_thumbnail) { if ('coupon' == $post->post_type) { echo '<div class="text-center code-data">'; $percent = hocwp_get_coupon_percent_label($post_id); $text = hocwp_get_coupon_text_label($post_id); $type_text = 'Website Coupons'; $type_term = hocwp_get_coupon_type_term($post_id); if (is_a($type_term, 'WP_Term')) { $type_text = $type_term->name; } $tmp = hocwp_get_coupon_type($post_id); if (is_array($tmp)) { $tmp = array_shift($tmp); if (!empty($tmp)) { $type_text = $tmp; } } $price = hocwp_get_post_meta('price', $post_id); $sale_price = hocwp_get_post_meta('sale_price', $post_id); if (!empty($price) && !empty($sale_price) || empty($percent)) { $percentage = hocwp_percentage($price, $sale_price); $percent = $percentage . '%'; $text = 'OFF'; } ?> <div class="txt"><?php echo $percent . ' ' . $text; ?> </div> <div class="type"><?php echo $type_text; ?> </div> <?php echo '</div>'; } else { $thumbnail_args = array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1]); if ($full_width) { unset($thumbnail_args['width']); unset($thumbnail_args['height']); } hocwp_post_thumbnail($thumbnail_args); } } do_action('hocwp_widget_post_before_post_title', $args, $instance, $this); hocwp_post_title_link(array('title' => hocwp_substr(get_the_title(), $title_length))); do_action('hocwp_widget_post_after_post_title', $args, $instance, $this); if (0 < $excerpt_length) { $post_type = get_post_type($post_id); if ('product' == $post_type && hocwp_wc_installed()) { hocwp_wc_product_price(null, true); } else { hocwp_entry_summary($excerpt_length); } } do_action('hocwp_widget_post_after_post', $args, $instance, $this); ?> </li> <?php $count++; } wp_reset_postdata(); $loop_html .= ob_get_clean(); } $widget_html .= $loop_html; $widget_html .= '</ul>'; return $widget_html; }
function hocwp_wc_single_product_fast_buy_button($args = array()) { $use = hocwp_wc_use_fast_buy_button(); if ($use) { global $product; $backup = $product; $post_id = hocwp_get_value_by_key($args, 'post_id'); $post_id = hocwp_return_post($post_id, 'id'); $tmp = new WC_Product($product); $product = $tmp; $show_button = (bool) hocwp_get_value_by_key($args, 'show_button', true); hocwp_div_clear(); do_action('hocwp_wc_before_fast_buy_button'); if ($show_button) { $args['post_id'] = $post_id; hocwp_wc_product_fast_buy_button($args); } ?> <div id="productBuy<?php echo $post_id; ?> " role="dialog" tabindex="-1" class="modal fade product-fast-buy"> <div class="modal-dialog"> <div class="modal-content clearfix"> <div class="modal-header"> <button aria-label="Close" data-dismiss="modal" class="close" type="button"><span aria-hidden="true">×</span></button> <h4 class="modal-title"><?php _e('Fast order', 'hocwp-theme'); ?> </h4> </div> <div class="modal-body"> <div class="row row-medium"> <div class="col-xs-12 col-md-6 info-column"> <div class="product-info"> <?php hocwp_post_thumbnail(array('bfi_thumb' => false, 'loop' => false)); hocwp_post_title_single(array('tag' => 'h2')); $get_variations = sizeof($product->get_children()) <= apply_filters('woocommerce_ajax_variation_threshold', 30, $product); $attributes = array(); if (hocwp_wc_is_variable($product)) { $tmp = new WC_Product_Variable($product); $product = $tmp; $attributes = $product->get_variation_attributes(); } $attribute_keys = array_keys($attributes); //$selected_attributes = $product->get_variation_default_attributes(); $available_variations = false; if (hocwp_wc_is_variable($product)) { $available_variations = $get_variations ? $product->get_available_variations() : false; } if (empty($available_variations) && false !== $available_variations) { ?> <p class="stock out-of-stock"><?php _e('This product is currently out of stock and unavailable.', 'hocwp-theme'); ?> </p> <?php } else { ?> <?php if (hocwp_array_has_value($attributes)) { ?> <form class="variations_form cart attributes-form" method="post"> <table class="variations" cellspacing="0"> <tbody> <?php foreach ($attributes as $attribute_name => $options) { ?> <tr> <td class="label"><label for="<?php echo sanitize_title($attribute_name); ?> "><?php echo wc_attribute_label($attribute_name); ?> </label> </td> <td class="value"> <?php $selected = isset($_REQUEST['attribute_' . sanitize_title($attribute_name)]) ? wc_clean($_REQUEST['attribute_' . sanitize_title($attribute_name)]) : $product->get_variation_default_attribute($attribute_name); wc_dropdown_variation_attribute_options(array('options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected)); echo end($attribute_keys) === $attribute_name ? apply_filters('woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __('Clear', 'hocwp-theme') . '</a>') : ''; ?> </td> </tr> <?php } ?> </tbody> </table> </form> <?php } ?> <?php } hocwp_wc_product_price(null, true); ?> </div> </div> <div class="col-xs-12 col-md-6 customer-column"> <div class="customer-info"> <?php $name = ''; $email = ''; $phone = ''; $address = ''; if (is_user_logged_in()) { $current = wp_get_current_user(); $name = get_user_meta($current->ID, 'billing_first_name', true); $last_name = get_user_meta($current->ID, 'billing_last_name', true); if (!empty($last_name)) { $name = $last_name . ' ' . $name; } $name = trim($name); if (empty($name)) { $name = $current->display_name; } $email = get_user_meta($current->ID, 'billing_email', true); if (!is_email($email)) { $email = $current->user_email; } $phone = get_user_meta($current->ID, 'billing_phone', true); $address = get_user_meta($current->ID, 'billing_address_1', true); } ?> <form class="order-form" method="post"> <div class="form-group"> <p><?php echo sprintf(__('Required fields are marked as %s', 'hocwp-theme'), HOCWP_REQUIRED_HTML); ?> </p> </div> <div class="form-group"> <input type="text" required aria-required="true" value="<?php echo $name; ?> " class="full-name form-control" placeholder="<?php _e('Full name *', 'hocwp-theme'); ?> " name="fullname"> </div> <div class="form-group"> <input type="text" class="phone form-control" value="<?php echo $phone; ?> " placeholder="<?php _e('Phone', 'hocwp-theme'); ?> " name="phone"> </div> <div class="form-group"> <input type="text" required aria-required="true" value="<?php echo $email; ?> " class="email form-control" placeholder="<?php _e('Email *', 'hocwp-theme'); ?> " name="email"> </div> <div class="form-group"> <input type="text" class="address form-control" value="<?php echo $address; ?> " placeholder="<?php _e('Address', 'hocwp-theme'); ?> " name="address"> </div> <div class="form-group"> <label for="message"><?php _e('Note:', 'hocwp-theme'); ?> </label> <textarea id="message" name="message" class="message form-control"></textarea> </div> <div class="form-group"> <button class="btn-clickable orange" data-id="<?php echo $post_id; ?> "> <span><?php _e('Put order', 'hocwp-theme'); ?> </span> </button> </div> </form> </div> </div> </div> </div> </div> </div> </div> <?php $product = $backup; } }