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


PHP WC_Product::add_to_cart_url方法代码示例

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


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

示例1: woocommerce_product_add_to_cart_url

/**
 * Get the add to cart URL for a product
 **/
function woocommerce_product_add_to_cart_url($atts)
{
    if (empty($atts)) {
        return;
    }
    global $wpdb;
    if ($atts['id']) {
        $product_data = get_post($atts['id']);
    } elseif ($atts['sku']) {
        $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $atts['sku']));
        $product_data = get_post($product_id);
    } else {
        return;
    }
    if ($product_data->post_type !== 'product') {
        return;
    }
    $_product = new WC_Product($product_data->ID);
    return esc_url($_product->add_to_cart_url());
}
开发者ID:rosslavery,项目名称:woocommerce,代码行数:23,代码来源:shortcode-init.php

示例2: array

global $mdf_loop;
?>
<div class="clearfix"></div>
<?php 
while ($mdf_loop->have_posts()) {
    $mdf_loop->the_post();
    ?>
<div class="aff_offer_links">
<?php 
    $i = 1;
    $product = new WC_Product(get_the_ID());
    global $product;
    ?>
    
<?php 
    $woolink = $product->product_type == 'external' ? $product->add_to_cart_url() : get_post_permalink(get_the_ID());
    $term_ids = wp_get_post_terms(get_the_ID(), 'product_tag', array("fields" => "ids"));
    if (!empty($term_ids)) {
        $term_brand = $term_ids[0];
        $term_brand_image = get_option("taxonomy_term_{$term_ids['0']}");
    } else {
        $term_brand_image = '';
    }
    ?>
<div class="rehub_feat_block table_view_block"><a name="woo-link-list"></a>
    <?php 
    if ($product->is_on_sale()) {
        ?>
<div class="vip_corner"><span class="vip_badge sale_badge">Sale!</span></div><?php 
    }
    ?>
开发者ID:rhondamoananui,项目名称:rehub,代码行数:31,代码来源:index.php

示例3: widget


//.........这里部分代码省略.........
                    }
                }
                ?>
							                </ul>
						                </li>
					                <?php 
            }
            ?>
				                </ul>
			                <?php 
        }
        ?>
		                </div>
	                </div>

                    <?php 
        $product_widget_cat = new WP_Query(array('post_type' => 'product', 'showposts' => 2, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $cat))));
        ?>
                        <?php 
        if ($product_widget_cat->have_posts()) {
            ?>
                        <div class="row sample">
	                        <?php 
            while ($product_widget_cat->have_posts()) {
                $product_widget_cat->the_post();
                ?>
	                        <div class="col-xs-6 sample-item">
		                        <div class="thumbnail">
			                        <a href="<?php 
                the_permalink();
                ?>
">
				                        <?php 
                product_percent_2();
                ?>
				                        <span class="sale-title">SALE</span>
				                        <span class="new-title">NEW</span>
				                        <?php 
                the_post_thumbnail(array(236, 330, 'bfi_thumb' => true), array('class' => 'img-responsive'));
                ?>
			                        </a>

			                        <div class="caption clearfix">
				                        <a href="<?php 
                the_permalink();
                ?>
"><span class="caption-title"><?php 
                hhs_brand();
                ?>
</span></a>
				                        <hr/>
				                        <?php 
                $product = new WC_Product(get_the_ID());
                ?>
				                        <p class="caption-description"><?php 
                echo get_the_title() . $product->get_sku();
                ?>
</p>

				                        <div class="caption-price">
					                        <?php 
                $price = get_post_meta(get_the_ID(), '_regular_price', true);
                $sale = get_post_meta(get_the_ID(), '_sale_price', true);
                ?>
					                        <div class="price-info">
						                        <?php 
                echo '<p class="old-price">' . number_format($price, 0, '.', '.') . ' VNĐ</p>';
                ?>
						                        <?php 
                echo '<p class="new-price">' . number_format($sale, 0, '.', '.') . ' VNĐ</p>';
                ?>
					                        </div>
					                        <div class="cart">
						                        <a href="<?php 
                echo esc_url($product->add_to_cart_url());
                ?>
"><img src="<?php 
                echo get_template_directory_uri();
                ?>
/img/product-cart.png"></a>
					                        </div>
				                        </div>
			                        </div>
		                        </div>
	                        </div>
	                        <?php 
            }
            wp_reset_postdata();
            ?>
                        </div>
                        <?php 
        }
        ?>
                    </div>
                    <!-- /.row row-no-padding -->
                </div>
            </section>
            <!-- /.section section-product -->
        <?php 
    }
开发者ID:Nguyenkain,项目名称:hanghieusales,代码行数:101,代码来源:show_product_list_widget.php

示例4: etheme_product_add_to_cart

/**
 * Display a single prodcut price + cart button
 *
 * @access public
 * @param array $atts
 * @return string
 */
function etheme_product_add_to_cart($atts)
{
    if (empty($atts)) {
        return;
    }
    global $wpdb, $woocommerce;
    if (!isset($atts['style'])) {
        $atts['style'] = '';
    }
    if ($atts['id']) {
        $product_data = get_post($atts['id']);
    } elseif ($atts['sku']) {
        $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $atts['sku']));
        $product_data = get_post($product_id);
    } else {
        return;
    }
    if ($product_data->post_type == 'product') {
        $product = $woocommerce->setup_product_data($product_data);
        ob_start();
        ?>
		<p class="product-add-to-cart" style="<?php 
        echo $atts['style'];
        ?>
">

			<?php 
        echo $product->get_price_html();
        ?>

			<?php 
        woocommerce_template_loop_add_to_cart();
        ?>

		</p><?php 
        return ob_get_clean();
    } elseif ($product_data->post_type == 'product_variation') {
        $product = new WC_Product($product_data->post_parent);
        $GLOBALS['product'] = $product;
        $variation = new WC_Product_Variation($product_data->ID);
        ob_start();
        ?>
		<p class="product-add-to-cart product-variation" style="<?php 
        echo $atts['style'];
        ?>
">

			<?php 
        echo $product->get_price_html();
        ?>

			<?php 
        $link = $product->add_to_cart_url();
        $label = apply_filters('add_to_cart_text', __('Add to cart', ETHEME_DOMAIN));
        $link = add_query_arg('variation_id', $variation->variation_id, $link);
        foreach ($variation->variation_data as $key => $data) {
            if ($data) {
                $link = add_query_arg($key, $data, $link);
            }
        }
        printf('<a href="%s" rel="nofollow" data-product_id="%s" class="button add_to_cart_button product_type_%s">%s</a>', esc_url($link), $product->id, $product->product_type, $label);
        ?>

		</p><?php 
        return ob_get_clean();
    }
}
开发者ID:donpapa26,项目名称:bakancslistad,代码行数:74,代码来源:woo.php

示例5:

									<div class="caption-price">
										<?php 
        $price = get_post_meta(get_the_ID(), '_regular_price', true);
        $sale = get_post_meta(get_the_ID(), '_sale_price', true);
        ?>
										<div class="price-info">
											<?php 
        echo '<p class="old-price">' . number_format($price, 0, '.', '.') . ' VNĐ</p>';
        ?>
											<?php 
        echo '<p class="new-price">' . number_format($sale, 0, '.', '.') . ' VNĐ</p>';
        ?>
										</div>
										<div class="cart">
											<a href="<?php 
        echo esc_url($product->add_to_cart_url());
        ?>
"><img src="<?php 
        echo get_template_directory_uri();
        ?>
/img/product-cart.png"></a>
										</div>
									</div>
								</div>
							</div>

						<?php 
    }
    // end of the loop.
    ?>
开发者ID:Nguyenkain,项目名称:hanghieusales,代码行数:30,代码来源:taxonomy-product_tag.php

示例6:

							</a>
						</th>
					</tr>
					<?php 
while ($products->have_posts()) {
    ?>
						<tr>
							<?php 
    $products->the_post();
    ?>
							<?php 
    $p = new WC_Product(get_the_ID());
    ?>
							<td><div>
								<a href="<?php 
    echo $p->add_to_cart_url();
    ?>
">
									<?php 
    echo $p->get_image(array(30, 30)) . ' ';
    the_title();
    ?>
								</a>
							</div></td>
							<td><div><?php 
    echo $p->get_price_html();
    ?>
</div></td>
							<td class="add"><a data-shop="<?php 
    the_ID();
    ?>
开发者ID:s7web,项目名称:shopByLook,代码行数:31,代码来源:single.php


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