Example #1
0
			<tbody>
				<?php 
    foreach ($attributes as $attribute_name => $options) {
        ?>
					<tr>
						<td class="lpd-varation-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, 'class' => 'form-control'));
        echo end($attribute_keys) === $attribute_name ? apply_filters('woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __('Clear', 'woocommerce') . '</a>') : '';
        ?>
						</td>
					</tr>
		        <?php 
    }
    ?>
			</tbody>
		</table>

		<?php 
    do_action('woocommerce_before_add_to_cart_button');
    ?>

		<div class="single_variation_wrap">
 /**
  * Output a list of variation attributes for use in the cart forms.
  *
  * @since 4.13.1
  * @param array $args
  */
 public static function wc_dropdown_variation_attribute_options($args = array())
 {
     if (self::is_wc_version_gte_2_4()) {
         return wc_dropdown_variation_attribute_options($args);
     } else {
         $args = wp_parse_args($args, array('options' => false, 'attribute' => false, 'product' => false, 'selected' => false, 'name' => '', 'id' => '', 'show_option_none' => __('Choose an option', 'woocommerce')));
         $options = $args['options'];
         $product = $args['product'];
         $attribute = $args['attribute'];
         $name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute);
         $id = $args['id'] ? $args['id'] : sanitize_title($attribute);
         if (empty($options) && !empty($product) && !empty($attribute)) {
             $attributes = $product->get_variation_attributes();
             $options = $attributes[$attribute];
         }
         echo '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" data-attribute_name="attribute_' . esc_attr(sanitize_title($attribute)) . '">';
         if ($args['show_option_none']) {
             echo '<option value="">' . esc_html($args['show_option_none']) . '</option>';
         }
         if (!empty($options)) {
             if ($product && taxonomy_exists($attribute)) {
                 // Get terms if this is a taxonomy - ordered. We need the names too.
                 $terms = self::wc_get_product_terms($product->id, $attribute, array('fields' => 'all'));
                 foreach ($terms as $term) {
                     if (in_array($term->slug, $options)) {
                         echo '<option value="' . esc_attr($term->slug) . '" ' . selected(sanitize_title($args['selected']), $term->slug, false) . '>' . apply_filters('woocommerce_variation_option_name', $term->name) . '</option>';
                     }
                 }
             } else {
                 foreach ($options as $option) {
                     echo '<option value="' . esc_attr(sanitize_title($option)) . '" ' . selected($args['selected'], sanitize_title($option), false) . '>' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</option>';
                 }
             }
         }
         echo '</select>';
     }
 }
			<?php 
    foreach ($attributes as $attribute_name => $options) {
        ?>

				<p for="<?php 
        echo sanitize_title($attribute_name);
        ?>
">
					<strong><?php 
        echo wc_attribute_label($attribute_name);
        ?>
: </strong></p>
				<div 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));
        ?>
				</div>

			<?php 
    }
    ?>

		</div>

		<?php 
    do_action('woocommerce_before_add_to_cart_button');
    ?>

		<div class="single_variation_wrap">
			<?php 
Example #4
0
				<?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 
        $default = sprintf(__('Choose a %s', 'swiftframework'), wc_attribute_label($attribute_name));
        $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, 'show_option_none' => $default));
        echo end($attribute_keys) === $attribute_name ? '<a class="reset_variations" href="#">' . __('Clear selection', 'swiftframework') . '</a>' : '';
        ?>
						</td>
					</tr>
		        <?php 
    }
    ?>
			</tbody>
		</table>

		<?php 
    do_action('woocommerce_before_add_to_cart_button');
    ?>

		<div class="single_variation_wrap">
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;
    }
}
 /**
  * @param $attribute_name
  * @param $options
  */
 function dropdown_variation_attribute($attribute_name, $options)
 {
     global $product;
     $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));
 }
 /**
  * Renders field input element.
  *
  * @param  string $field_key
  * @param  array  $field_config
  * @return string
  */
 public function render_input($field_key, array $field_config)
 {
     $type = isset($field_config['type']) ? $field_config['type'] : 'text';
     $value = '';
     if (!isset($this->field_vals[$field_key])) {
         if (isset($field_config['default'])) {
             $value = $field_config['default'];
         }
     } else {
         $value = $this->field_vals[$field_key];
     }
     $name = isset($field_config['name']) ? $field_config['name'] : $field_key;
     $errors = isset($this->field_errors[$field_key]) ? $this->field_errors[$field_key] : array();
     $attributes = !empty($field_config['attributes']) ? $field_config['attributes'] : array();
     $attributes['name'] = $name;
     $transparent_attributes = array('id', 'class');
     foreach ($transparent_attributes as $att_name) {
         if (!empty($field_config[$att_name])) {
             $attributes[$att_name] = $field_config[$att_name];
         }
     }
     if ($errors) {
         $attributes['title'] = join('<br>', $errors);
     }
     $result = '';
     switch ($type) {
         case 'select':
             $options_html = '';
             if (!empty($field_config['options'])) {
                 $options_html = $this->render_options($field_config['options'], $value);
             }
             $result = sprintf('<select %s>%s</select>', $this->render_field_attributes($attributes, $field_key, $field_config), $options_html);
             break;
         case 'variation_select':
             $args = $field_config;
             if (!isset($args['selected'])) {
                 $args['selected'] = $value ? $value : (isset($args['default']) ? $args['default'] : '');
             }
             if (!isset($args['show_option_none']) && !empty($field_config['label'])) {
                 $args['show_option_none'] = $field_config['label'];
             }
             ob_start();
             wc_dropdown_variation_attribute_options($args);
             $result = ob_get_clean();
             break;
         case 'textarea':
             if (!empty($field_config['placeholder'])) {
                 $attributes['placeholder'] = $field_config['placeholder'];
             }
             $textarea_attributes = $attributes;
             unset($textarea_attributes['type']);
             $result = sprintf('<textarea %s>%s</textarea>', $this->render_field_attributes($textarea_attributes, $field_key, $field_config), $value);
             break;
         case 'text':
         case 'hidden':
         case 'number':
         default:
             $attributes['value'] = $value;
             if (in_array($type, array('hidden', 'number', 'date', 'text'))) {
                 $attributes['type'] = $type;
             } else {
                 $attributes['type'] = 'text';
             }
             if (!empty($field_config['placeholder'])) {
                 $attributes['placeholder'] = $field_config['placeholder'];
             }
             $result = sprintf('<input %s>', $this->render_field_attributes($attributes, $field_key, $field_config));
             /*if ( 'date' == $name ) {
             			$options_html = '';
             			if ( ! empty( $field_config['options'] ) ) {
             				$options_html = $this->render_options( $field_config['options'], $value );
             			}
             			$result = sprintf( '<select %s>%s</select>', $this->render_field_attributes( $attributes, $field_key, $field_config ), $options_html );
             		}*/
             break;
     }
     return $result;
 }
			<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, 'show_option_none' => apply_filters('uni_asana_show_option_none_variation_filter', __('Choose an option', 'asana'), wc_attribute_label($attribute_name))));
        echo end($attribute_keys) === $attribute_name ? '<a class="reset_variations" href="#">' . __('Clear selection', 'woocommerce') . '</a>' : '';
        ?>
						</td>
					</tr>
		        <?php 
    }
    ?>
			</tbody>
		</table>

		<?php 
    do_action('woocommerce_before_add_to_cart_button');
    ?>

		<div class="single_variation_wrap" style="display:none;">