Example #1
0
function hocwp_get_slider_items($post_id = null, $sanitize = true)
{
    $post_id = hocwp_return_post($post_id, 'id');
    $items = hocwp_get_post_meta('slider_items', $post_id);
    $items = hocwp_sanitize_slider_item($items);
    return $items;
}
Example #2
0
function hocwp_product_price($post_id = null, $no_price = '', $args = array())
{
    $post_id = hocwp_return_post($post_id, 'id');
    $regular_price = hocwp_get_post_meta('regular_price', $post_id);
    $sale_price = hocwp_get_post_meta('sale_price', $post_id);
    $prices = hocwp_sanitize_product_price($regular_price, $sale_price, $post_id);
    $price = $prices['price'];
    $no_price_html = '<span class="no-price">' . __('Price', 'hocwp-theme') . ': <span class="amount">';
    $no_price_html .= __('Please call', 'hocwp-theme') . '</span></span>';
    $defaults = array('currency' => '$', 'currency_position' => 'left', 'decimals' => 2, 'dec_point' => '.', 'thousands_sep' => ',', 'no_price_html' => $no_price_html);
    $defaults = apply_filters('hocwp_product_price_defaults', $defaults);
    $args = wp_parse_args($args, $defaults);
    $no_price_html = $args['no_price_html'];
    if (empty($no_price)) {
        $no_price = $no_price_html;
    }
    if (!hocwp_is_positive_number($price)) {
        $price = $no_price;
    } else {
        $sale_price = $prices['sale_price'];
        $regular_price = $prices['regular_price'];
        $currency = hocwp_get_value_by_key($args, 'currency');
        $currency = apply_filters('hocwp_product_price_currency', $currency);
        $currency_position = hocwp_get_value_by_key($args, 'currency_position', 'left');
        $currency_position = apply_filters('hocwp_product_price_currency_position', $currency_position);
        $decimals = hocwp_get_value_by_key($args, 'decimals');
        $dec_point = hocwp_get_value_by_key($args, 'dec_point');
        $thousands_sep = hocwp_get_value_by_key($args, 'thousands_sep');
        $number_format = '%NUMBER%';
        if ('left' == $currency_position) {
            $number_format = '%CURRENCY%' . $number_format;
        } else {
            $number_format .= '%CURRENCY%';
        }
        $number_format = str_replace('%CURRENCY%', $currency, $number_format);
        $price = number_format($regular_price, $decimals, $dec_point, $thousands_sep);
        $price = str_replace('%NUMBER%', $price, $number_format);
        $price = hocwp_wrap_tag($price, 'span', 'amount');
        if (hocwp_is_positive_number($sale_price)) {
            $sale_price = number_format($sale_price, $decimals, $dec_point, $thousands_sep);
            $sale_price = str_replace('%NUMBER%', $sale_price, $number_format);
            $sale_price = hocwp_wrap_tag($sale_price, 'span', 'amount');
            $sale_price = hocwp_wrap_tag($sale_price, 'ins');
            $price = hocwp_wrap_tag($price, 'del');
            $price .= $sale_price;
        }
    }
    if (!empty($price)) {
        $price = hocwp_wrap_tag($price, 'p', 'price');
        echo $price;
    }
}
Example #3
0
function hocwp_get_post_comment_count($post_id = null, $status = 'approved')
{
    $post_id = hocwp_return_post($post_id, 'id');
    $comments = get_comment_count($post_id);
    return hocwp_get_value_by_key($comments, $status);
}
Example #4
0
function hocwp_update_user_saved_posts($user_id = null, $post_id = null)
{
    $user_id = hocwp_return_user($user_id, 'id');
    if (hocwp_id_number_valid($user_id)) {
        $post_id = hocwp_return_post($post_id, 'id');
        if (hocwp_id_number_valid($post_id)) {
            $saved = hocwp_get_user_saved_posts($user_id);
            $saved = hocwp_sanitize_array($saved);
            if (in_array($post_id, $saved)) {
                unset($saved[array_search($post_id, $saved)]);
            } else {
                array_push($saved, $post_id);
            }
            $saved = hocwp_remove_empty_array_item($saved, true);
            return update_user_meta($user_id, 'saved_posts', $saved);
        }
    }
    return false;
}
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;
    }
}
Example #6
0
function hocwp_star_ratings($post_id = null)
{
    if (function_exists('kk_star_ratings')) {
        $post_id = hocwp_return_post($post_id, 'id');
        echo kk_star_ratings($post_id);
    }
}