本文整理汇总了PHP中wc_dropdown_variation_attribute_options函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_dropdown_variation_attribute_options函数的具体用法?PHP wc_dropdown_variation_attribute_options怎么用?PHP wc_dropdown_variation_attribute_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_dropdown_variation_attribute_options函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
<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">
示例2: wc_dropdown_variation_attribute_options
/**
* 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>';
}
}
示例3: foreach
<?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
示例4: foreach
<?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">
示例5: hocwp_wc_single_product_fast_buy_button
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);
//.........这里部分代码省略.........
示例6: dropdown_variation_attribute
/**
* @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));
}
示例7: render_input
/**
* 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;
}
示例8: foreach
<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;">