本文整理汇总了PHP中wc_setup_product_data函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_setup_product_data函数的具体用法?PHP wc_setup_product_data怎么用?PHP wc_setup_product_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_setup_product_data函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: shortcode_custom_add_to_cart
function shortcode_custom_add_to_cart($atts, $content = null)
{
global $wpdb, $post;
if (empty($atts)) {
return '';
}
extract(shortcode_atts(array('id' => '', 'quantity' => '1', 'sku' => '', 'show_price' => 'true', 'size' => '', 'style' => '', 'align' => '', 'text_color' => '', 'bg_color' => ''), $atts));
if (!empty($id)) {
$product_data = get_post($id);
} elseif (!empty($sku)) {
$product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku));
$product_data = get_post($product_id);
} else {
return '';
}
$product = wc_setup_product_data($product_data);
if (!$product) {
return '';
}
ob_start();
$class = "vc_btn " . $size . ' ' . $style;
?>
<p class="product woocommerce add_to_cart_inline" style="text-align:<?php
echo $align;
?>
">
<?php
if ($show_price == 'true') {
?>
<?php
echo $product->get_price_html();
?>
<?php
}
?>
<span class="add_to_cart_separator"></span>
<?php
echo apply_filters('woocommerce_loop_add_to_cart_link', sprintf("<a style=\"color: {$text_color}; background-color: {$bg_color};\" href=\"%s\" rel=\"nofollow\" data-product_id=\"%s\" data-product_sku=\"%s\" data-quantity=\"%s\" class=\"{$class} %s product_type_%s\"><span>%s</span></a>", esc_url($product->add_to_cart_url()), esc_attr($product->id), esc_attr($product->get_sku()), esc_attr(isset($quantity) ? $quantity : 1), $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '', esc_attr($product->product_type), esc_html($product->add_to_cart_text())), $product);
?>
</p>
<?php
wp_reset_query();
$content = ob_get_contents();
ob_end_clean();
wc_setup_product_data($post);
return $content;
}
开发者ID:Junaid-Farid,项目名称:gocnex,代码行数:52,代码来源:add-to-cart.php
示例2: product_add_to_cart
/**
* Display a single product price + cart button
*
* @param array $atts
* @return string
*/
public static function product_add_to_cart($atts)
{
global $wpdb, $post;
if (empty($atts)) {
return '';
}
$atts = shortcode_atts(array('id' => '', 'class' => '', 'quantity' => '1', 'sku' => '', 'style' => 'border:4px solid #ccc; padding: 12px;', 'show_price' => 'true'), $atts);
if (!empty($atts['id'])) {
$product_data = get_post($atts['id']);
} elseif (!empty($atts['sku'])) {
$product_id = wc_get_product_id_by_sku($atts['sku']);
$product_data = get_post($product_id);
} else {
return '';
}
$product = wc_setup_product_data($product_data);
if (!$product) {
return '';
}
ob_start();
?>
<p class="product woocommerce add_to_cart_inline <?php
echo $atts['class'];
?>
" style="<?php
echo $atts['style'];
?>
">
<?php
if ('true' == $atts['show_price']) {
?>
<?php
echo $product->get_price_html();
?>
<?php
}
?>
<?php
woocommerce_template_loop_add_to_cart(array('quantity' => $atts['quantity']));
?>
</p><?php
// Restore Product global in case this is shown inside a product post
wc_setup_product_data($post);
return ob_get_clean();
}
开发者ID:ayoayco,项目名称:upbeat,代码行数:54,代码来源:class-wc-shortcodes.php
示例3: product_add_to_cart_url
/**
* Get the add to cart URL for a product.
*
* @param array $atts
* @return string
*/
public static function product_add_to_cart_url($atts)
{
global $wpdb;
if (empty($atts)) {
return '';
}
if (isset($atts['id'])) {
$product_data = get_post($atts['id']);
} elseif (isset($atts['sku'])) {
$product_id = wc_get_product_id_by_sku($atts['sku']);
$product_data = get_post($product_id);
} else {
return '';
}
$product = is_object($product_data) && in_array($product_data->post_type, array('product', 'product_variation')) ? wc_setup_product_data($product_data) : false;
if (!$product) {
return '';
}
$_product = wc_get_product($product_data);
return esc_url($_product->add_to_cart_url());
}
开发者ID:seriusokhatsky,项目名称:woocommerce,代码行数:27,代码来源:class-wc-shortcodes.php
示例4: setup_product_data
/**
* @deprecated 2.1.0
* @param $post
* @return WC_Product
*/
public function setup_product_data($post)
{
_deprecated_function('Woocommerce->setup_product_data', '2.1', 'wc_setup_product_data');
return wc_setup_product_data($post);
}
开发者ID:donwea,项目名称:nhap.org,代码行数:10,代码来源:woocommerce.php
示例5: wcviews_setup_product_data
public function wcviews_setup_product_data($post)
{
if (function_exists('wc_setup_product_data')) {
//Using WooCommerce Plugin version 2.1+
$product_information = wc_setup_product_data($post);
return $product_information;
} else {
//Probably still using older woocommerce versions
global $woocommerce;
if (is_object($woocommerce)) {
$product_information = $woocommerce->setup_product_data($post);
return $product_information;
}
}
}
开发者ID:rebeccayshen,项目名称:kitlist,代码行数:15,代码来源:Class_WooCommerce_Views.php
示例6: foreach
<nav class="jcarousel-controls">
<a class="jcarousel-prev" href="#"></a>
<a class="jcarousel-next" href="#"></a>
</nav>
<div class="jcarousel-wrapper">
<div class="meals-of-the-day-jcarousel jcarousel off">
<ul class="products">
<?php
foreach ($meals_slider_result as $slider) {
?>
<?php
$slider_post = get_post($slider->product_id);
$slide_link = get_permalink($slider->product_id);
if ($slider_post->post_type == 'product') {
$product = wc_setup_product_data($slider_post);
$price = $product->get_price_html();
} else {
$price = '';
}
?>
<li class="meal product">
<div class="img-holder">
<a href="<?php
echo $slide_link;
?>
">
<?php
$slide_img = get_post_meta($slider->product_id, '_daymeals-slider-input', true);
if ($slide_img != '') {
echo "<img src='{$slide_img}' alt='' />";
开发者ID:jyri363,项目名称:pizzakuller-themes,代码行数:31,代码来源:index.php
示例7: product_add_to_cart_url
/**
* Get the add to cart URL for a product.
*
* @param array $atts
* @return string
*/
public static function product_add_to_cart_url($atts)
{
global $wpdb;
if (empty($atts)) {
return '';
}
if (isset($atts['id'])) {
$product_data = get_post($atts['id']);
} elseif (isset($atts['sku'])) {
$product_id = wc_get_product_id_by_sku($atts['sku']);
$product_data = get_post($product_id);
} else {
return '';
}
if (is_object($product_data)) {
$product = wc_setup_product_data($product_data);
} else {
return '';
}
if ('product' !== $product_data->post_type) {
return '';
}
$_product = wc_get_product($product_data);
return esc_url($_product->add_to_cart_url());
}
开发者ID:estrategasdigitales,项目名称:venone,代码行数:31,代码来源:class-wc-shortcodes.php
示例8: product_add_to_cart
/**
* Display a single product price + cart button
*
* @access public
* @param array $atts
* @return string
*/
public static function product_add_to_cart($atts)
{
global $wpdb, $post;
if (empty($atts)) {
return '';
}
extract(shortcode_atts(array('id' => '', 'sku' => '', 'style' => 'border:4px solid #ccc; padding: 12px;', 'show_price' => 'true'), $atts));
if (!empty($id)) {
$product_data = get_post($id);
} elseif (!empty($sku)) {
$product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku));
$product_data = get_post($product_id);
} else {
return '';
}
$product = wc_setup_product_data($product_data);
if (!$product) {
return '';
}
ob_start();
?>
<p class="product woocommerce" style="<?php
echo $style;
?>
">
<?php
if ($show_price == 'true') {
?>
<?php
echo $product->get_price_html();
?>
<?php
}
?>
<?php
woocommerce_template_loop_add_to_cart();
?>
</p><?php
// Restore Product global in case this is shown inside a product post
wc_setup_product_data($post);
return ob_get_clean();
}
开发者ID:prosenjit-itobuz,项目名称:nutraperfect,代码行数:52,代码来源:class-wc-shortcodes.php
示例9: wd_best_selling_product_slider_function
//.........这里部分代码省略.........
<?php
echo $extra_class_row;
?>
<?php
echo strlen(trim($big_product)) > 0 ? 'big_product' : '';
?>
" id="<?php
echo $_random_id;
?>
">
<?php
if (strlen(trim($title)) > 0 || strlen(trim($desc)) > 0) {
?>
<header class="shortcode-title-wrapper">
<?php
if (strlen(trim($title)) > 0) {
echo "<h3 class='heading-title slider-title'>" . esc_html($title) . "</h3>";
}
?>
</header>
<?php
if (strlen(trim($desc)) > 0) {
echo "<p class='slider-desc-wrapper'>" . esc_html($desc) . "</p>";
}
?>
<?php
}
?>
<?php
if (isset($_big_prod) && $_big_prod->is_visible()) {
$_product = wc_get_product($_big_prod->id);
$post = $_product->post;
$extra_class = 'col-sm-12';
$product = wc_setup_product_data($post);
$image_title = esc_attr($_product->get_title());
$product_link = esc_url($_product->get_permalink());
$image = get_the_post_thumbnail($post->ID, apply_filters('single_product_large_thumbnail_size', 'shop_single'), array('alt' => $image_title, 'title' => $image_title));
echo '<div class="wd-big-product product ' . $extra_class . '">';
echo sprintf('<div class="wd_image product-thumbnail-wrapper"><a title="%s" href="%s">%s</a></div>', $image_title, $product_link, $image);
echo '<div class="wd_meta product-meta-wrapper"><p class="price">' . $_product->get_price_html() . '</p>';
woocommerce_template_loop_add_to_cart();
//echo $temp_add_to_cart_data;
echo '</div></div>';
wc_setup_product_data($post);
}
?>
<div class="<?php
echo $show_type;
?>
product-slider-wrapper ">
<div class="product-slider-inner loading">
<?php
$current_row = 0;
?>
<?php
woocommerce_product_loop_start();
?>
<?php
$woocommerce_loop['columns'] = 1;
?>
<?php
开发者ID:mynein,项目名称:myne,代码行数:67,代码来源:best_selling_product_slider.php
注:本文中的wc_setup_product_data函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论