当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Product::has_child方法代码示例

本文整理汇总了PHP中WC_Product::has_child方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::has_child方法的具体用法?PHP WC_Product::has_child怎么用?PHP WC_Product::has_child使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Product的用法示例。


在下文中一共展示了WC_Product::has_child方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: is_bulk_variation_form

 public function is_bulk_variation_form()
 {
     global $post;
     if (!$post) {
         return false;
     }
     /** Remove validation (_bv_type) -- 03/02/2016 **/
     if (!is_product()) {
         return false;
     }
     /****/
     /** Validate if exits role -- 03/02/2016 **/
     if ($this->role_exists('wholesale_customer')) {
         if (!current_user_can('wholesale_customer')) {
             return false;
         }
     }
     // 2.0 Compat
     if (function_exists('get_product')) {
         $product = get_product($post->ID);
     } else {
         $product = new WC_Product($post->ID);
     }
     if ($product && !$product->has_child() && !$product->is_type('variable')) {
         return false;
     }
     return apply_filters('woocommerce_bv_render_form', true);
 }
开发者ID:jmagallanes,项目名称:cultura-woo-bulk-variations,代码行数:28,代码来源:cultura-woo-bulk-variations.php

示例2: get_variation_id

 /**
  * Given a product ID & variations, find the correct variation ID to use for
  * calculation. We can't just trust input from the CLI to pass a variation_id
  * manually, otherwise you could pass the cheapest variation ID but provide
  * other information so we have to look up the variation ID.
  *
  * @since  2.5.0
  * @param  WC_Product $product Product instance
  * @return int                 Returns an ID if a valid variation was found for this product
  */
 protected function get_variation_id($product, $variations = array())
 {
     $variation_id = null;
     $variations_normalized = array();
     if ($product->is_type('variable') && $product->has_child()) {
         if (isset($variations) && is_array($variations)) {
             // start by normalizing the passed variations
             foreach ($variations as $key => $value) {
                 $key = str_replace('attribute_', '', str_replace('pa_', '', $key));
                 // from get_attributes in class-wc-api-products.php
                 $variations_normalized[$key] = strtolower($value);
             }
             // now search through each product child and see if our passed variations match anything
             foreach ($product->get_children() as $variation) {
                 $meta = array();
                 foreach (get_post_meta($variation) as $key => $value) {
                     $value = $value[0];
                     $key = str_replace('attribute_', '', str_replace('pa_', '', $key));
                     $meta[$key] = strtolower($value);
                 }
                 // if the variation array is a part of the $meta array, we found our match
                 if ($this->array_contains($variations_normalized, $meta)) {
                     $variation_id = $variation;
                     break;
                 }
             }
         }
     }
     return $variation_id;
 }
开发者ID:jgcopple,项目名称:drgaryschwantz,代码行数:40,代码来源:class-wc-cli-order.php

示例3: extract

    function get_form($options)
    {
        global $woocommerce;
        $product = null;
        if (function_exists('get_product')) {
            $product = get_product($this->product_id);
        } else {
            $product = new WC_Product($this->product_id);
        }
        extract(shortcode_atts(array('display_title' => true, 'display_description' => true, 'display_inactive' => false, 'field_values' => false, 'ajax' => false, 'tabindex' => 1, 'label_subtotal' => __('Subtotal', 'wc_gf_addons'), 'label_options' => __('Options', 'wc_gf_addons'), 'label_total' => __('Total', 'wc_gf_addons'), 'disable_label_subtotal' => 'no', 'disable_label_options' => 'no', 'disable_label_total' => 'no', 'disable_calculations' => 'no'), $options));
        //Get the form meta so we can make sure the form exists.
        $form_meta = RGFormsModel::get_form_meta($this->form_id);
        if (!empty($form_meta)) {
            if (!empty($_POST)) {
                $_POST['gform_submit'] = isset($_POST['gform_old_submit']) ? $_POST['gform_old_submit'] : '';
                $_POST['gform_old_submit'] = $_POST['gform_submit'];
            }
            $form = RGForms::get_form($this->form_id, $display_title, $display_description, $display_inactive, $field_values, $ajax, $tabindex);
            unset($_POST['gform_submit']);
            $form = str_replace('</form>', '', $form);
            $form = str_replace('gform_submit', 'gform_old_submit', $form);
            $this->current_page = GFFormDisplay::get_current_page($this->form_id);
            $this->next_page = $this->current_page + 1;
            $this->previous_page = $this->current_page - 1;
            $this->next_page = $this->next_page > $this->get_max_page_number($form_meta) ? 0 : $this->next_page;
            if ($product->product_type == 'variable' || $product->product_type == 'variable-subscription') {
                echo '<div class="gform_variation_wrapper gform_wrapper single_variation_wrap">';
            } else {
                echo '<div class="gform_variation_wrapper gform_wrapper">';
            }
            if ($product->is_type('variable')) {
                //echo '<input type="hidden" name="add-to-cart" value="variation" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            } elseif ($product->has_child()) {
                //echo '<input type="hidden" name="add-to-cart" value="group" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            } else {
                //echo '<input type="hidden" name="add-to-cart" value="' . $this->product_id . '" />';
                echo '<input type="hidden" id="product_id" name="product_id" value="' . $this->product_id . '" />';
            }
            if (wc_is_21x()) {
                wp_nonce_field('add_to_cart');
            } else {
                $woocommerce->nonce_field('add_to_cart');
            }
            echo '<a id="_form_' . $this->form_id . '" href="#_form_' . $this->form_id . '" class="gform_anchor"></a>';
            echo $form;
            echo '<input type="hidden" name="gform_form_id" id="gform_form_id" value="' . $this->form_id . '" />';
            echo '<input type="hidden" id="woocommerce_get_action" value="" />';
            echo '<input type="hidden" id="woocommerce_product_base_price" value="' . $product->get_price() . '" />';
            $description_class = rgar($form_meta, "descriptionPlacement") == "above" ? "description_above" : "description_below";
            ?>

			<?php 
            $this->on_print_scripts();
            if ($disable_calculations == 'no') {
                ?>

				<div class="product_totals">
					<ul id="gform_totals_<?php 
                echo $this->form_id;
                ?>
" class="gform_fields <?php 
                echo $form_meta['labelPlacement'] . ' ' . $description_class;
                ?>
">
						<li class="gfield" <?php 
                if ($disable_label_subtotal == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
							<label class="gfield_label"><?php 
                echo $label_subtotal;
                ?>
</label>
							<div class="ginput_container">
								<span class="formattedBasePrice ginput_total"></span>
							</div>
						</li>
						<li class="gfield" <?php 
                if ($disable_label_options == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
							<label class="gfield_label"><?php 
                echo $label_options;
                ?>
</label>
							<div class="ginput_container">
								<span class="formattedVariationTotal ginput_total"></span>
							</div>
						</li>
						<li class="gfield" <?php 
                if ($disable_label_total == 'yes') {
                    echo 'style="display:none;"';
                }
                ?>
 >
//.........这里部分代码省略.........
开发者ID:avijitdeb,项目名称:flatterbox.com,代码行数:101,代码来源:gravityforms-product-addons-form.php

示例4: create_variation_selector

    private function create_variation_selector($condition, $name)
    {
        global $post;
        $post_id = isset($_POST['post']) ? intval($_POST['post']) : $post->ID;
        if (!$post_id) {
            return;
        }
        $product = null;
        if (function_exists('get_product')) {
            $product = get_product($post_id);
        } else {
            $product = new WC_Product($post_id);
        }
        if (!$product->has_child()) {
            return;
        }
        $all_variations = $product->get_children();
        $div_style = $condition['args']['type'] != 'variations' ? 'display:none;' : '';
        ?>

		<div>
			<label for="pricing_rule_variations_<?php 
        echo $name;
        ?>
"><?php 
        _e('Product / Variations:', 'wc_pricing');
        ?>
</label>
			<select title="<?php 
        _e('Choose what you would like to apply this pricing rule set to', 'wc_pricing');
        ?>
" class="pricing_rule_variations" id="pricing_rule_variations_<?php 
        echo $name;
        ?>
" name="pricing_rules[<?php 
        echo $name;
        ?>
][variation_rules][args][type]">
				<option <?php 
        selected('product', $condition['args']['type']);
        ?>
 value="product"><?php 
        _e('All Variations', 'wc_pricing');
        ?>
</option>
				<option <?php 
        selected('variations', $condition['args']['type']);
        ?>
 value="variations"><?php 
        _e('Specific Variations', 'wc_pricing');
        ?>
</option>
			</select>

			<div class="variations" style="<?php 
        echo $div_style;
        ?>
">
				<?php 
        sort($all_variations);
        ?>
				<?php 
        $chunks = array_chunk($all_variations, ceil(count($all_variations) / 3), true);
        ?>

				<?php 
        foreach ($chunks as $chunk) {
            ?>

					<ul class="list-column">        
						<?php 
            foreach ($chunk as $variation_id) {
                ?>
							<?php 
                $variation_object = new WC_Product_Variation($variation_id);
                ?>
							<?php 
                $variation_checked = isset($condition['args']['variations']) && is_array($condition['args']['variations']) && in_array($variation_id, $condition['args']['variations']) ? 'checked="checked"' : '';
                ?>
							<li>
								<label for="variation_<?php 
                echo $variation_id;
                ?>
_<?php 
                echo $name;
                ?>
" class="selectit">
									<input <?php 
                echo $variation_checked;
                ?>
 type="checkbox" id="variation_<?php 
                echo $variation_id;
                ?>
_<?php 
                echo $name;
                ?>
" name="pricing_rules[<?php 
                echo $name;
                ?>
][variation_rules][args][variations][]" value="<?php 
//.........这里部分代码省略.........
开发者ID:arobbins,项目名称:spellestate,代码行数:101,代码来源:product_pricing_rules_admin.class.php

示例5: elseif

 function woocommerce_gravityform()
 {
     global $post, $woocommerce;
     include_once 'gravityforms-product-addons-form.php';
     $gravity_form_data = get_post_meta($post->ID, '_gravity_form_data', true);
     if (is_array($gravity_form_data) && $gravity_form_data['id']) {
         $product = null;
         if (function_exists('get_product')) {
             $product = get_product($post->ID);
         } else {
             $product = new WC_Product($post->ID);
         }
         $product_form = new woocommerce_gravityforms_product_form($gravity_form_data['id'], $post->ID);
         $product_form->get_form($gravity_form_data);
         $add_to_cart_value = '';
         if ($product->is_type('variable')) {
             $add_to_cart_value = 'variation';
         } elseif ($product->has_child()) {
             $add_to_cart_value = 'group';
         } else {
             $add_to_cart_value = $product->id;
         }
         if (!function_exists('get_product')) {
             //1.x only
             $woocommerce->nonce_field('add_to_cart');
             echo '<input type="hidden" name="add-to-cart" value="' . $add_to_cart_value . '" />';
         } else {
             echo '<input type="hidden" name="add-to-cart" value="' . $post->ID . '" />';
         }
     }
     echo '<div class="clear"></div>';
 }
开发者ID:avijitdeb,项目名称:flatterbox.com,代码行数:32,代码来源:gravityforms-product-addons.php

示例6: display_form

        /**
         * Display the form associated to the product
         */
        public function display_form()
        {
            global $post, $woocommerce;
            if ($this->apply_addon()) {
                $product = null;
                if (function_exists('get_product')) {
                    $product = get_product($post->ID);
                } else {
                    $product = new WC_Product($post->ID);
                }
                $form_content = cp_calculatedfieldsf_filter_content($this->form);
                // Initialize form fields
                if (!empty($_SESSION['cp_cff_form_data']) && !empty($_REQUEST['cp_calculatedfieldsf_id']) && !empty($_REQUEST['cp_calculatedfieldsf_pform_psequence'])) {
                    global $wpdb;
                    $result = $wpdb->get_row($wpdb->prepare("SELECT form_data.paypal_post AS paypal_post FROM " . CP_CALCULATEDFIELDSF_POSTS_TABLE_NAME . " AS form_data WHERE form_data.id=%d AND form_data.formid=%d", $_SESSION['cp_cff_form_data'], $_REQUEST['cp_calculatedfieldsf_id']));
                    if (!is_null($result)) {
                        $arr = array();
                        $submitted_data = unserialize($result->paypal_post);
                        foreach ($submitted_data as $key => $val) {
                            if (preg_match('/^fieldname\\d+$/', $key)) {
                                $arr[$key . $_REQUEST['cp_calculatedfieldsf_pform_psequence']] = $val;
                            }
                        }
                        ?>
						<script>
							cpcff_default  = ( typeof cpcff_default != 'undefined' ) ? cpcff_default : {};
							cpcff_default[ 'form_structure<?php 
                        echo $_REQUEST['cp_calculatedfieldsf_pform_psequence'];
                        ?>
' ] = <?php 
                        echo json_encode($arr);
                        ?>
;
						</script>
				<?php 
                    }
                }
                unset($_SESSION['cp_cff_form_data']);
                // Remove the form tags
                if (preg_match('/<form[^>]*>/', $form_content, $match)) {
                    $form_content = str_replace($match[0], '', $form_content);
                    $form_content = preg_replace('/<\\/form>/', '', $form_content);
                }
                $tmp = get_post_meta($post->ID, 'woocommerce_cpcff_calculate_price', true);
                $request_cost = !empty($tmp) ? cp_calculatedfieldsf_get_option('request_cost', false, $this->form['id']) : false;
                echo '<div class="cpcff-woocommerce-wrapper">' . $form_content . (method_exists($woocommerce, 'nonce_field') ? $woocommerce->nonce_field('add_to_cart') : '') . '<input type="hidden" name="woocommerce_cpcff_product" value="' . $post->ID . '" />' . ($request_cost ? '<input type="hidden" name="woocommerce_cpcff_field" value="' . $request_cost . '" /><input type="hidden" name="woocommerce_cpcff_form" value="' . $this->form['id'] . '">' : '') . '</div>';
                $add_to_cart_value = '';
                if ($product->is_type('variable')) {
                    $add_to_cart_value = 'variation';
                } elseif ($product->has_child()) {
                    $add_to_cart_value = 'group';
                } else {
                    $add_to_cart_value = $product->id;
                }
                if (!function_exists('get_product')) {
                    //1.x only
                    if (method_exists($woocommerce, 'nonce_field')) {
                        $woocommerce->nonce_field('add_to_cart');
                    }
                    echo '<input type="hidden" name="add-to-cart" value="' . $add_to_cart_value . '" />';
                } else {
                    echo '<input type="hidden" name="add-to-cart" value="' . $post->ID . '" />';
                }
            }
            echo '<div class="clear"></div>';
        }
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:69,代码来源:woocommerce.addon.php


注:本文中的WC_Product::has_child方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。