本文整理汇总了PHP中WC_Product::get_price_html方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product::get_price_html方法的具体用法?PHP WC_Product::get_price_html怎么用?PHP WC_Product::get_price_html使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product
的用法示例。
在下文中一共展示了WC_Product::get_price_html方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_product_data
/**
* Get standard product data that applies to every product type
*
* @since 2.1
* @param WC_Product $product
* @return array
*/
private function get_product_data($product)
{
return array('title' => $product->get_name(), 'id' => $product->get_id(), 'created_at' => $this->server->format_datetime($product->get_date_created(), false, true), 'updated_at' => $this->server->format_datetime($product->get_date_modified(), false, true), 'type' => $product->get_type(), 'status' => $product->get_status(), 'downloadable' => $product->is_downloadable(), 'virtual' => $product->is_virtual(), 'permalink' => $product->get_permalink(), 'sku' => $product->get_sku(), 'price' => wc_format_decimal($product->get_price(), 2), 'regular_price' => wc_format_decimal($product->get_regular_price(), 2), 'sale_price' => $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : null, 'price_html' => $product->get_price_html(), 'taxable' => $product->is_taxable(), 'tax_status' => $product->get_tax_status(), 'tax_class' => $product->get_tax_class(), 'managing_stock' => $product->managing_stock(), 'stock_quantity' => $product->get_stock_quantity(), 'in_stock' => $product->is_in_stock(), 'backorders_allowed' => $product->backorders_allowed(), 'backordered' => $product->is_on_backorder(), 'sold_individually' => $product->is_sold_individually(), 'purchaseable' => $product->is_purchasable(), 'featured' => $product->is_featured(), 'visible' => $product->is_visible(), 'catalog_visibility' => $product->get_catalog_visibility(), 'on_sale' => $product->is_on_sale(), 'weight' => $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : null, 'dimensions' => array('length' => $product->get_length(), 'width' => $product->get_width(), 'height' => $product->get_height(), 'unit' => get_option('woocommerce_dimension_unit')), 'shipping_required' => $product->needs_shipping(), 'shipping_taxable' => $product->is_shipping_taxable(), 'shipping_class' => $product->get_shipping_class(), 'shipping_class_id' => 0 !== $product->get_shipping_class_id() ? $product->get_shipping_class_id() : null, 'description' => apply_filters('the_content', $product->get_description()), 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), 'reviews_allowed' => $product->get_reviews_allowed(), 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), 'rating_count' => $product->get_rating_count(), 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), 'categories' => wc_get_object_terms($product->get_id(), 'product_cat', 'name'), 'tags' => wc_get_object_terms($product->get_id(), 'product_tag', 'name'), 'images' => $this->get_images($product), 'featured_src' => wp_get_attachment_url(get_post_thumbnail_id($product->get_id())), 'attributes' => $this->get_attributes($product), 'downloads' => $this->get_downloads($product), 'download_limit' => $product->get_download_limit(), 'download_expiry' => $product->get_download_expiry(), 'download_type' => 'standard', 'purchase_note' => apply_filters('the_content', $product->get_purchase_note()), 'total_sales' => $product->get_total_sales(), 'variations' => array(), 'parent' => array());
}
示例2: woocs_product
function woocs_product($ID, $attr, $currency = true)
{
if (class_exists('WC_Product')) {
$product = new WC_Product($ID);
if ($attr == 'price_tax_inc') {
$p = round($product->get_price_including_tax(), 2);
} elseif ($attr == 'get_price_excluding_tax') {
$p = round($product->get_price_excluding_tax(), 2);
} elseif ($attr == 'get_price') {
$p = round($product->get_price(), 2);
} elseif ($attr == 'get_sale_price') {
$p = round($product->get_sale_price(), 2);
} elseif ($attr == 'get_regular_price') {
$p = round($product->get_regular_price(), 2);
} elseif ($attr == 'get_price_html') {
$p = strip_tags($product->get_price_html());
} elseif ($attr == 'is_in_stock') {
$p = $product->is_in_stock();
}
}
return $p;
}
示例3: vc_gitem_template_attribute_woocommerce_product
/**
* Gte woocommerce data for product
*
* @param $value
* @param $data
*
* @return string
*/
function vc_gitem_template_attribute_woocommerce_product($value, $data)
{
$label = '';
/**
* @var null|Wp_Post $post ;
* @var string $data ;
*/
extract(array_merge(array('post' => null, 'data' => ''), $data));
require_once WC()->plugin_path() . '/includes/abstracts/abstract-wc-product.php';
$product = new WC_Product($post);
if (preg_match('/_labeled$/', $data)) {
$data = preg_replace('/_labeled$/', '', $data);
$label = apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_label', Vc_Vendor_Woocommerce::getProductFieldLabel($data) . ': ');
}
$price_format = get_woocommerce_price_format();
switch ($data) {
case 'id':
$value = (int) $product->is_type('variation') ? $product->get_variation_id() : $product->id;
break;
case 'sku':
$value = $product->get_sku();
break;
case 'price':
$value = sprintf($price_format, wc_format_decimal($product->get_price(), 2), get_woocommerce_currency());
break;
case 'regular_price':
$value = sprintf($price_format, wc_format_decimal($product->get_regular_price(), 2), get_woocommerce_currency());
break;
case 'sale_price':
$value = sprintf(get_woocommerce_price_format(), $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : '', get_woocommerce_currency());
break;
case 'price_html':
$value = $product->get_price_html();
break;
case 'reviews_count':
$value = count(get_comments(array('post_id' => $post->ID, 'approve' => 'approve')));
break;
case 'short_description':
$value = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt);
break;
case 'dimensions':
$units = get_option('woocommerce_dimension_unit');
$value = $product->length . $units . 'x' . $product->width . $units . 'x' . $product->height . $units;
break;
case 'raiting_count':
$value = $product->get_rating_count();
break;
case 'weight':
$value = $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : '';
break;
case 'on_sale':
$value = $product->is_on_sale() ? 'yes' : 'no';
// @todo change
break;
default:
$value = $product->{$data};
}
return strlen($value) > 0 ? $label . apply_filters('vc_gitem_template_attribute_woocommerce_product_' . $data . '_value', $value) : '';
}
示例4: hocwp_wc_product_price
function hocwp_wc_product_price($post_id = null, $show_full = false)
{
if ($show_full) {
if (!hocwp_id_number_valid($post_id)) {
$post_id = get_the_ID();
}
$product = new WC_Product($post_id);
$html = $product->get_price_html();
$html = hocwp_wrap_tag($html, 'p', 'prices price');
echo $html;
} else {
$price = hocwp_wc_get_product_price($post_id);
echo hocwp_wc_format_price($price);
}
}
示例5: alfw_slider_render_func
//.........这里部分代码省略.........
echo '<div class="cycle-caption"></div>';
//echo '<div class="cycle-overlay"></div>';
}
}
/**
* Showing nawigation buttons
*/
if ($slider[0]['show_navigation'] && $slider_count > 1) {
$hover = '';
if ($slider[0]['navigation_on_hover_state_only']) {
$hover = 'hover';
}
echo '
<div class="slide_commands ' . $hover . '">
<div class="slide_play" style="display: none;"></div>
<div class="slide_stop" style="display: block;"></div>
</div>';
echo '<div class="slide-prev ' . $hover . '"><span></span></div>';
echo '<div class="slide-next ' . $hover . '"><span></span></div>';
}
foreach ($slides as &$slide) {
/**
* Add to hotspot product information
*/
$hotspots = json_decode($slide['hotsposts']);
if (!empty($hotspots)) {
foreach ($hotspots as &$point) {
/**
* $point->sku - it's post id not product sku
*/
if (!empty($point->sku) && is_numeric($point->sku)) {
$post_data = get_post($point->sku, ARRAY_A);
$product = new WC_Product($post_data['ID']);
$price = $product->get_price_html();
$stock_status = $product->is_in_stock() ? 'In stock' : 'Out of stock';
$product_url = get_permalink($post_data['ID']);
$url = wp_get_attachment_image_src(get_post_thumbnail_id($post_data['ID']));
$status_block = '';
$price_block = '';
$text_block = '';
$addcart_block = '';
$img_block = '';
if ($show_desc) {
$img_block = !empty($url[0]) ? '<img src="' . $url[0] . '" style="width:50px" />' : '';
}
switch ($post_data['post_type']) {
case 'post':
if ($show_desc) {
$text_block = mb_substr(strip_tags($post_data['post_content']), 0, 100);
}
break;
case 'page':
if ($show_desc) {
$text_block = mb_substr(strip_tags($post_data['post_content']), 0, 100);
}
break;
case 'product':
$status_block = '<div class="out-of-stock"><span>' . $stock_status . '</span></div>';
$price_block = '<div class="price">' . $price . '</div>';
if ($show_desc) {
$text_block = mb_substr(strip_tags($post_data['post_excerpt']), 0, 100);
}
if ($show_addcart) {
$addcart_block = '<div class="add-to-cart">
<form method="post" action="' . esc_url($product_url) . '">
<input type="hidden" value="' . $post_data['ID'] . '" name="add-to-cart">
示例6: sysProductLoop
function sysProductLoop($category_name, $number_posts)
{
if (empty($number_posts)) {
$number_posts = -1;
}
$args = array('showposts' => $number_posts, 'product_cat' => $category_name, 'post_type' => 'product');
$loop = new WP_Query($args);
if ($loop->have_posts()) {
?>
<section class="loop__products masonry__grid">
<?php
while ($loop->have_posts()) {
$loop->the_post();
// gets the loop__product info
$product = new WC_Product(get_the_ID());
$product_price = $product->get_price_html();
// gets the group info
$groups = new Groups_Post_Access();
$groups_post = $groups->get_read_post_capabilities(get_the_ID());
?>
<div class="loop__product masonry__item"<?php
// adds all groups applied to loop__product to the attribute 'data-machines'
if (!empty($groups)) {
$x = 0;
echo 'data-machines="';
foreach ($groups_post as $group) {
if ($x > 0) {
echo " ";
} else {
$x++;
}
$group_sort = strtolower($group);
$group_sort = str_replace('|', '', $group_sort);
$group_sort = str_replace(' ', '-', $group_sort);
$group_sort = str_replace('--', '-', $group_sort);
echo $group_sort;
}
echo '"';
}
?>
>
<a href="<?php
the_permalink();
?>
" class="loop__product__link">
<?php
// if loop__product has image
if (get_the_post_thumbnail()) {
// get loop__product image
$url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
?>
<div class="loop__product__image__container">
<img data-layzr="<?php
echo $url[0];
?>
" alt="<?php
the_title();
?>
image" class="loop__product__image">
</div>
<?php
}
?>
<div class="loop__product__header">
<h2 class="loop__product__title"><?php
echo ucwords(get_the_title());
?>
</h2>
<p class="loop__product__price"><?php
echo $product_price;
?>
</p>
</div>
<?php
if (get_the_excerpt()) {
$x = get_the_excerpt();
echo '<p class="loop__product__excerpt">' . $x . '</p>';
}
?>
</a>
</div>
<?php
}
// END | While $loop->have_posts();
?>
</section>
<?php
}
// END | If $loop->have_posts()
// to make sure that any wp_query's after don't use the same $args
wp_reset_query();
}
示例7: array
//.........这里部分代码省略.........
foreach ($front_edit_reverse as $key => $value) {
if ($key == $sort_by) {
echo '<div>' . __("Sort Criterion", "ts_visual_composer_extend") . ': ' . $value . '</div>';
}
}
$front_edit_reverse = array("asc" => __('Bottom to Top', "ts_visual_composer_extend"), "desc" => __('Top to Bottom', "ts_visual_composer_extend"));
foreach ($front_edit_reverse as $key => $value) {
if ($key == $sort_order) {
echo '<div>' . __("Initial Order", "ts_visual_composer_extend") . ': ' . $value . '</div>';
}
}
echo '<div>' . __("Show Filter Button", "ts_visual_composer_extend") . ': ' . $filter_menu . '</div>';
echo '<div>' . __("Show Layout Button", "ts_visual_composer_extend") . ': ' . $layout_menu . '</div>';
echo '<div>' . __("Show Sort Criterion Button", "ts_visual_composer_extend") . ': ' . $sort_menu . '</div>';
echo '<div>' . __("Show Directions Buttons", "ts_visual_composer_extend") . ': ' . $directions_menu . '</div>';
echo '</div>';
} else {
$opening .= '<div id="' . $posts_container_id . '" class="ts-isotope-posts-grid-parent ' . ($layout == 'spineTimeline' ? 'ts-timeline ' : 'ts-postsgrid ') . 'ts-timeline-' . $sort_order . ' ts-posts-timeline ' . $isotope_posts_list_class . ' ' . $css_class . '" style="margin-top: ' . $margin_top . 'px; margin-bottom: ' . $margin_bottom . ';" data-lazy="' . $posts_lazy . '" data-count="' . $posts_limit . '" data-ajax="' . $posts_ajax . '" data-trigger="' . $posts_trigger . '" data-column="' . $column_width . '" data-layout="' . $layout . '" data-sort="' . $sort_by . '" data-order="' . $sort_order . '" data-break="' . $layout_break . '" data-type="' . $post_type . '">';
// Create Individual Post Output
$postCounter = 0;
$postCategories = array();
$categoriesCount = 0;
if (post_type_exists($post_type) && $loop->have_posts()) {
$products .= '<div class="ts-timeline-content">';
$products .= '<ul id="ts-isotope-posts-grid-' . $postsgrid_random . '" class="ts-isotope-posts-grid ts-timeline-list" data-layout="' . $layout . '" data-key="' . $postsgrid_random . '">';
while ($loop->have_posts()) {
$loop->the_post();
$postCounter++;
$product_id = get_the_ID();
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$product_sku = $product->get_sku();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'true' : 'false';
$onsale = $product->is_on_sale() ? 'true' : 'false';
// Rating Settings
$rating_html = $product->get_rating_html();
$rating = $product->get_average_rating();
if ($rating == '') {
$rating = 0;
}
if ($rating_quarter == "true") {
$rating_value = floor($rating * 4) / 4;
} else {
$rating_value = $rating;
}
$rating_value = number_format($rating_value, 2, $caption_digits, '');
if ($rating_rtl == "false") {
$rating_width = $rating_value / $rating_maximum * 100;
} else {
$rating_width = 100 - $rating_value / $rating_maximum * 100;
}
if ($rating_symbol == "other") {
if ($rating_icon == "ts-ecommerce-starfull1") {
$rating_class = 'ts-rating-stars-star1';
} else {
if ($rating_icon == "ts-ecommerce-starfull2") {
$rating_class = 'ts-rating-stars-star2';
} else {
if ($rating_icon == "ts-ecommerce-starfull3") {
$rating_class = 'ts-rating-stars-star3';
} else {
if ($rating_icon == "ts-ecommerce-starfull4") {
示例8: content
protected function content($atts, $content = null)
{
$atts = function_exists('vc_map_get_attributes') ? vc_map_get_attributes('kt_featured_products', $atts) : $atts;
$atts = shortcode_atts(array('title' => __('Hot Categories', 'kutetheme'), 'box_type' => 'featured', 'ids' => '', 'number' => 4, 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
extract($atts);
$elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, ' trending ', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '));
$elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
ob_start();
$args = array('post_type' => 'product', 'meta_key' => '_featured', 'meta_value' => 'yes', 'posts_per_page' => $number);
if ($ids) {
$ids = explode(',', $ids);
} else {
$ids = array();
}
if ($box_type == 'by_id') {
$args = array('post_type' => 'product', 'post__in' => $ids);
}
$products = get_posts($args);
$count = count($products);
$per_page = 2;
$loop = false;
if ($count > 2) {
$loop = true;
}
?>
<div class=" <?php
echo esc_attr($elementClass);
?>
">
<?php
if ($title) {
?>
<h2 class="trending-title"><?php
echo esc_html($title);
?>
</h2>
<?php
}
?>
<div class="trending-product owl-carousel nav-center" data-items="1" data-dots="false" data-nav="true" data-autoplay="true" <?php
if ($loop) {
?>
data-loop="true" <?php
}
?>
>
<?php
$page = 1;
if ($count % $per_page == 0) {
$page = $count / $per_page;
} else {
$page = $count / $per_page + 1;
}
?>
<?php
for ($i = 1; $i <= $page; $i++) {
?>
<ul>
<?php
$from = ($i - 1) * $per_page;
$to = $i * $per_page;
for ($from; $from < $to; $from++) {
if (isset($products[$from]) && $products[$from]) {
$p = $products[$from];
$product = new WC_Product($p->ID);
?>
<li>
<div class="product-container">
<div class="product-image">
<a href="<?php
echo get_permalink($p->ID);
?>
">
<?php
echo get_the_post_thumbnail($p->ID, 'shop_thumbnai');
?>
</a>
</div>
<div class="product-info">
<h5 class="product-name">
<a href="<?php
echo get_permalink($p->ID);
?>
"><?php
echo esc_html($p->post_title);
?>
</a>
</h5>
<div class="product-price">
<?php
echo $product->get_price_html();
?>
</div>
</div>
</div>
</li>
<?php
}
}
?>
//.........这里部分代码省略.........
示例9: WooComposer_Loop_style04
//.........这里部分代码省略.........
}
if ($display_type == "product_categories") {
$args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => $ids, 'field' => 'term_id', 'operator' => 'IN'));
}
$test = '';
if (vc_is_inline()) {
$test = "wcmp_vc_inline";
}
if ($product_animation == '') {
$product_animation = 'no-animation';
} else {
$style .= 'opacity:1;';
}
if ($element == "grid") {
$class = 'vc_span' . $columns . ' ';
}
$output .= '<div class="woocomposer ' . $test . '" data-columns="' . $col . '">';
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$product_id = get_the_ID();
$uid = uniqid();
$output .= '<div id="product-' . $uid . '" style="' . $style . '" class="' . $class . ' wpb_column column_container wooproduct" data-animation="animated ' . $product_animation . '">';
if ($element == 'carousel') {
$output .= '<div class="wcmp-carousel-item">';
}
$product_title = get_the_title($product_id);
$post = get_post($product_id);
$product_desc = get_post($product_id)->post_excerpt;
$product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
$product = new WC_Product($product_id);
$attachment_ids = $product->get_gallery_attachment_ids();
$price = $product->get_price_html();
$rating = $product->get_rating_html();
$attributes = $product->get_attributes();
$stock = $product->is_in_stock() ? 'InStock' : 'OutOfStock';
if ($product->is_on_sale()) {
$on_sale = apply_filters('woocommerce_sale_flash', $label_on_sale, $post, $product);
} else {
$on_sale = '';
}
if ($quick_view_style == "expandable") {
$quick_view_class = 'quick-view-loop';
} else {
$quick_view_class = 'quick-view-loop-popup';
}
$cat_count = sizeof(get_the_terms($product_id, 'product_cat'));
$tag_count = sizeof(get_the_terms($product_id, 'product_tag'));
$categories = $product->get_categories(', ', '<span class="posted_in">' . _n('', '', $cat_count, 'woocommerce') . ' ', '.</span>');
$tags = $product->get_tags(', ', '<span class="tagged_as">' . _n('', '', $tag_count, 'woocommerce') . ' ', '.</span>');
$output .= "\n" . '<div class="wcmp-product woocommerce wcmp-' . $product_style . ' ' . $img_animate . '" style="' . $border . ' ' . $desc_style . '">';
$output .= "\n\t" . '<div class="wcmp-product-image">';
if (empty($attachment_ids) && count($attachment_ids) > 1 && $product_img_disp == "carousel") {
$uniqid = uniqid();
$output .= '<div class="wcmp-single-image-carousel carousel-in-loop">';
$product_img = wp_get_attachment_image_src(get_post_thumbnail_id($product_id), $image_size);
if ($lazy_images == "enable") {
$src = plugins_url('../assets/img/loader.gif', __FILE__);
} else {
$src = $product_img[0];
}
$output .= '<div><div class="wcmp-image"><img class="wcmp-img" src="' . $src . '" data-src="' . $product_img[0] . '"/></div></div>';
foreach ($attachment_ids as $attachment_id) {
$product_img = wp_get_attachment_image_src($attachment_id, $image_size);
if ($lazy_images == "enable") {
示例10: extract
/**
* Shows the course cost.
*
* @since 1.0.0
*/
function course_cost($atts)
{
global $coursepress;
extract(shortcode_atts(array('course_id' => in_the_loop() ? get_the_ID() : '', 'course' => false, 'label' => __('Price: ', 'cp'), 'label_tag' => 'strong', 'label_delimeter' => ': ', 'no_cost_text' => __('FREE', 'cp'), 'show_icon' => 'false', 'class' => ''), $atts, 'course_cost'));
$course_id = (int) $course_id;
$label = sanitize_text_field($label);
$label_tag = sanitize_html_class($label_tag);
$label_delimeter = sanitize_html_class($label_delimeter);
$no_cost_text = sanitize_text_field($no_cost_text);
$show_icon = sanitize_text_field($show_icon);
$class = sanitize_html_class($class);
$show_icon = 'true' == $show_icon ? true : false;
// Saves some overhead by not loading the post again if we don't need to.
$course = empty($course) ? new Course($course_id) : object_decode($course, 'Course');
$is_paid = get_post_meta($course_id, 'paid_course', true) == 'on' ? true : false;
$content = '';
if (cp_use_woo()) {
if ($is_paid) {
$woo_product = get_post_meta($course_id, 'woo_product', true);
$wc_product = new WC_Product($woo_product);
$content .= $wc_product->get_price_html();
} else {
if ($show_icon) {
$content .= '<span class="mp_product_price">' . $no_cost_text . '</span>';
} else {
$content .= $no_cost_text;
}
}
} else {
if ($is_paid && CoursePress::instance()->marketpress_active) {
$mp_product = get_post_meta($course_id, 'marketpress_product', true);
$content .= do_shortcode('[mp_product_price product_id="' . $mp_product . '" label=""]');
} else {
if ($show_icon) {
$content .= '<span class="mp_product_price">' . $no_cost_text . '</span>';
} else {
$content .= $no_cost_text;
}
}
}
if (!empty($content)) {
ob_start();
?>
<div class="course-cost course-cost-<?php
echo $course_id;
?>
<?php
echo $class;
?>
">
<?php
if (!empty($label)) {
?>
<<?php
echo $label_tag;
?>
class="label"><?php
echo $label;
echo $label_delimeter;
?>
</<?php
echo $label_tag;
?>
><?php
}
echo $content;
?>
</div>
<?php
$content = ob_get_clean();
}
// Return the html in the buffer.
return $content;
}
示例11: woocommerce_product_add_to_cart
/**
* Display a single prodcut price + cart button
**/
function woocommerce_product_add_to_cart($atts)
{
if (empty($atts)) {
return;
}
global $wpdb, $woocommerce;
if (!isset($atts['style'])) {
$atts['style'] = 'border:4px solid #ccc; padding: 12px;';
}
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);
if (!$product->is_visible()) {
continue;
}
ob_start();
?>
<p class="product" 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);
if (!$product->is_visible()) {
continue;
}
ob_start();
?>
<p class="product 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', 'woocommerce'));
$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);
}
}
echo sprintf('<a href="%s" 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();
}
}
示例12: get_price_html
/**
* Returns range style html price string without min and max.
*
* @param mixed $price default price
* @return string overridden html price string (old style)
*/
public function get_price_html($price = '')
{
if (!$this->is_synced()) {
$this->sync_composite();
}
if ($this->is_priced_per_product()) {
// Get the price.
if ($this->hide_price_html() || $this->min_composite_price === '') {
$price = apply_filters('woocommerce_composite_empty_price_html', '', $this);
} else {
$suppress_range_format = $this->suppress_range_format || apply_filters('woocommerce_composite_force_old_style_price_html', false, $this);
if ($suppress_range_format) {
$price = wc_price($this->get_composite_price('min', true));
if ($this->min_composite_regular_price > $this->min_composite_price) {
$regular_price = wc_price($this->get_composite_regular_price('min', true));
if ($this->min_composite_price !== $this->max_composite_price) {
$price = sprintf(_x('%1$s%2$s', 'Price range: from', 'woocommerce-composite-products'), $this->get_price_html_from_text(), $this->get_price_html_from_to($regular_price, $price) . $this->get_price_suffix());
} else {
$price = $this->get_price_html_from_to($regular_price, $price) . $this->get_price_suffix();
}
$price = apply_filters('woocommerce_composite_sale_price_html', $price, $this);
} elseif ($this->min_composite_price === 0 && $this->max_composite_price === 0) {
$free_string = apply_filters('woocommerce_composite_show_free_string', false, $this) ? __('Free!', 'woocommerce') : $price;
$price = apply_filters('woocommerce_composite_free_price_html', $free_string, $this);
} else {
if ($this->min_composite_price !== $this->max_composite_price) {
$price = sprintf(_x('%1$s%2$s', 'Price range: from', 'woocommerce-composite-products'), $this->get_price_html_from_text(), $price . $this->get_price_suffix());
} else {
$price = $price . $this->get_price_suffix();
}
$price = apply_filters('woocommerce_composite_price_html', $price, $this);
}
} else {
if ($this->min_composite_price !== $this->max_composite_price) {
$price = sprintf(_x('%1$s–%2$s', 'Price range: from-to', 'woocommerce'), wc_price($this->get_composite_price('min', true)), wc_price($this->get_composite_price('max', true)));
} else {
$price = wc_price($this->get_composite_price('min', true));
}
if ($this->min_composite_regular_price > $this->min_composite_price) {
if ($this->min_composite_regular_price !== $this->max_composite_regular_price) {
$regular_price = sprintf(_x('%1$s–%2$s', 'Price range: from-to', 'woocommerce'), wc_price($this->get_composite_regular_price('min', true)), wc_price($this->get_composite_regular_price('max', true)));
} else {
$regular_price = wc_price($this->get_composite_regular_price('min', true));
}
$price = apply_filters('woocommerce_composite_sale_price_html', $this->get_price_html_from_to($regular_price, $price) . $this->get_price_suffix(), $this);
} elseif ($this->min_composite_price === 0 && $this->max_composite_price === 0) {
$free_string = apply_filters('woocommerce_composite_show_free_string', false, $this) ? __('Free!', 'woocommerce') : $price;
$price = apply_filters('woocommerce_composite_free_price_html', $free_string, $this);
} else {
$price = apply_filters('woocommerce_composite_price_html', $price . $this->get_price_suffix(), $this);
}
}
}
return apply_filters('woocommerce_get_price_html', $price, $this);
} else {
return parent::get_price_html();
}
}
示例13: update
/**
* Update content block
*
* @param array of update value
*
* @return array of update block
*/
function update($params = array())
{
// Default values
$defaults = array('post_id' => false, 'block_id' => false, 'mode' => false, 'properties' => false);
// Parse args
$params = wp_parse_args($params, $defaults);
extract($params, EXTR_SKIP);
// Check minimum requirement parameter
if (!$post_id || !$block_id || !$mode || !$properties) {
return false;
}
// Get current value
$blocks = get_post_meta($post_id, '_wcng_blocks', true);
// If blocks 'is' still empty
if (!$blocks) {
$blocks = array();
}
// Update blocks value
$allow_args = array('product_id', 'text', 'image', 'link');
$properties = (array) $properties;
foreach ($properties as $arg_key => $arg) {
if (in_array($arg_key, $allow_args)) {
switch ($arg_key) {
case 'product_id':
$product_id = intval($arg);
$product_image_size = $properties['product_image_size'];
if ($product_id) {
$blocks[$block_id][$mode][$arg_key] = $product_id;
// Populate and store the product data
$blocks[$block_id][$mode]['title'] = get_the_title($product_id);
$blocks[$block_id][$mode]['permalink'] = get_permalink($product_id);
// Get the price
$wc_product = new WC_Product($product_id);
$blocks[$block_id][$mode]['price'] = strip_tags($wc_product->get_price_html());
// Get the thumbnail, if there's any
$post_thumbnail_id = get_post_thumbnail_id($product_id);
if ($post_thumbnail_id) {
$attachment_src = wp_get_attachment_image_src($post_thumbnail_id, $product_image_size);
// Check for image existence
if (isset($attachment_src[0])) {
$image = $attachment_src[0];
} else {
$image = WC_NEWSLETTER_GENERATOR_URL . 'assets/default-product-image.png';
}
} else {
$image = WC_NEWSLETTER_GENERATOR_URL . 'assets/default-product-image.png';
}
$blocks[$block_id][$mode]['image'] = $image;
}
break;
default:
$blocks[$block_id][$mode][$arg_key] = sanitize_text_field($arg);
break;
}
}
}
// Save the blocks value
update_post_meta($post_id, '_wcng_blocks', $blocks);
// Get the updated postmeta
$new_blocks = get_post_meta($post_id, '_wcng_blocks', true);
return $new_blocks[$block_id][$mode];
}
开发者ID:gregoriopellegrino,项目名称:woocommerce-newsletter-generator,代码行数:69,代码来源:class-wc-newsletter-generator-ajax.php
示例14: array
function woocommerce_products_live_search()
{
if (isset($_REQUEST['fn']) && 'get_ajax_search' == $_REQUEST['fn']) {
$query_args = array('posts_per_page' => 10, 'no_found_rows' => true, 'post_type' => 'product');
if (isset($_REQUEST['terms'])) {
$query_args['s'] = $_REQUEST['terms'];
}
$search_query = new WP_Query($query_args);
$results = array();
if ($search_query->get_posts()) {
foreach ($search_query->get_posts() as $the_post) {
$title = get_the_title($the_post->ID);
if (has_post_thumbnail($the_post->ID)) {
$post_thumbnail_ID = get_post_thumbnail_id($the_post->ID);
$post_thumbnail_src = wp_get_attachment_image_src($post_thumbnail_ID, 'thumbnail');
} else {
$dimensions = wc_get_image_size('thumbnail');
$post_thumbnail_src = array(wc_placeholder_img_src(), esc_attr($dimensions['width']), esc_attr($dimensions['height']));
}
$product = new WC_Product($the_post->ID);
$price = $product->get_price_html();
$brand = woocommerce_show_brand($the_post->ID, true);
$title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
$results[] = array('value' => $title, 'url' => get_permalink($the_post->ID), 'tokens' => explode(' ', $title), 'image' => $post_thumbnail_src[0], 'price' => $price, 'brand' => $brand);
}
} else {
$results[] = __('Sorry. No results match your search.', 'media_center');
}
wp_reset_postdata();
echo json_encode($results);
}
die;
}
示例15:
<?php
the_title(sprintf('<h4><a href="%s" rel="bookmark">', esc_url(get_permalink())), '</a></h4>');
?>
<div class="eone-product-content-description">
<?php
the_excerpt();
?>
</div><!-- .eone-product-content-description -->
</div><!-- .eone-product-content -->
<div class="eone-product-price">
<?php
$ecom_product = new WC_Product(get_the_ID());
$ecom_price = $ecom_product->get_price_html();
if ($ecom_price) {
echo '<p><span>' . $ecom_price . '</span></p>';
}
?>
</div><!-- .eone-product-price -->
<div class="eone-product-buy">
<span><a href="<?php
echo esc_url(get_permalink());
?>
">
<?php
if (of_get_option('eone_latest_section_buy_text')) {