本文整理汇总了PHP中WC_Product_Variation::get_title方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variation::get_title方法的具体用法?PHP WC_Product_Variation::get_title怎么用?PHP WC_Product_Variation::get_title使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product_Variation
的用法示例。
在下文中一共展示了WC_Product_Variation::get_title方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: woocommerce_add_order_item
function woocommerce_add_order_item()
{
global $woocommerce, $wpdb;
check_ajax_referer('add-order-item', 'security');
$index = trim(stripslashes($_POST['index']));
$item_to_add = trim(stripslashes($_POST['item_to_add']));
$post = '';
// Find the item
if (is_numeric($item_to_add)) {
$post = get_post($item_to_add);
}
if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') {
$post_id = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT post_id\n\t\t\tFROM {$wpdb->posts}\n\t\t\tLEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\n\t\t\tWHERE {$wpdb->postmeta}.meta_key = '_sku'\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\tAND {$wpdb->posts}.post_type = 'shop_product'\n\t\t\tAND {$wpdb->postmeta}.meta_value = %s\n\t\t\tLIMIT 1\n\t\t"), $item_to_add);
$post = get_post($post_id);
}
if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') {
die;
}
if ($post->post_type == "product") {
$_product = new WC_Product($post->ID);
} else {
$_product = new WC_Product_Variation($post->ID);
}
?>
<tr class="item" rel="<?php
echo $index;
?>
">
<td class="product-id">
<img class="tips" tip="<?php
echo '<strong>' . __('Product ID:', 'woocommerce') . '</strong> ' . $_product->id;
echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> ';
if (isset($_product->variation_id) && $_product->variation_id) {
echo $_product->variation_id;
} else {
echo '-';
}
echo '<br/><strong>' . __('Product SKU:', 'woocommerce') . '</strong> ';
if ($_product->sku) {
echo $_product->sku;
} else {
echo '-';
}
?>
" src="<?php
echo $woocommerce->plugin_url();
?>
/assets/images/tip.png" />
</td>
<td class="sku">
<?php
if ($_product->sku) {
echo $_product->sku;
} else {
echo '-';
}
?>
<input type="hidden" class="item_id" name="item_id[<?php
echo $index;
?>
]" value="<?php
echo esc_attr($_product->id);
?>
" />
<input type="hidden" name="item_name[<?php
echo $index;
?>
]" value="<?php
echo esc_attr($_product->get_title());
?>
" />
<input type="hidden" name="item_variation[<?php
echo $index;
?>
]" value="<?php
if (isset($_product->variation_id)) {
echo $_product->variation_id;
}
?>
" />
</td>
<td class="name">
<div class="row-actions">
<span class="trash"><a class="remove_row" href="#"><?php
_e('Delete item', 'woocommerce');
?>
</a> | </span>
<span class="view"><a href="<?php
echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
?>
"><?php
_e('View product', 'woocommerce');
?>
</a>
</div>
<?php
echo $_product->get_title();
?>
//.........这里部分代码省略.........
示例2: printPage
//.........这里部分代码省略.........
$args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC');
// Loop Product Variation
$loop = new WP_Query($args);
while ($loop->have_posts()) {
$loop->the_post();
$product = new WC_Product_Variation($loop->post->ID);
$attrs = array();
if ($product->variation_data != "") {
$terms = wc_get_attribute_taxonomies();
foreach ($terms as $term) {
$termMap['attribute_pa_' . $term->attribute_name] = $term->attribute_label;
}
foreach ($product->variation_data as $attributeKey => $value) {
if (isset($termMap[$attributeKey])) {
$attrs[] = $termMap[$attributeKey] . " : " . $value;
} else {
$attrs[] = $value;
}
}
}
/*
$colore = get_post_meta( get_the_ID(), 'attribute_pa_color', true );
$taglia = get_post_meta( get_the_ID(), 'attribute_pa_taglia', true );
*/
?>
<tr class="order">
<td class="thumb column-thumb" ><?php
echo $product->get_image($size = 'shop_thumbnail');
?>
</td>
<td class="order-number" style="text-transform:uppercase"><?php
echo $product->get_title();
?>
</td>
<td class="order-number"><?php
echo get_the_title($loop->post->post_parent);
?>
</td>
<td class="order-number"><?php
echo $product->sku;
?>
</td>
<td class="order-number"><?php
echo $product->regular_price;
?>
<strong>€</strong></td>
<td class="order-number" style="color:#F00"><?php
echo $product->sale_price;
?>
</td>
<td class="order-number" style="text-transform:uppercase"><?php
echo join("<strong> / </strong>", $attrs);
?>
</td>
<td class="order-number"><?php
echo $product->stock;
?>
<strong>pezzi</strong></td>
<td style="float:right;" class="order-number"><?php
echo apply_filters('woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>', esc_url($product->add_to_cart_url('/alter-inventory/')), esc_attr($product->id), esc_attr($product->get_sku()), $product->is_purchasable() ? 'add_to_cart_button' : '', esc_attr($product->product_type), esc_html($product->add_to_cart_text())), $product);
?>
</td>
示例3: yml_offers
/**
* Generate YML body with offers.
*
* @since 0.3.0
* @param $currency
* @param $query
*
* @return string
*/
private function yml_offers($currency, $query)
{
$yml = '';
while ($query->have_posts()) {
$query->the_post();
$product = wc_get_product($query->post->ID);
// We use a seperate variable for offer because we will be rewriting it for variable products.
$offer = $product;
/*
* By default we set $variation_count to 1.
* That means that there is at least one product available.
* Variation products will have more than 1 count.
*/
$variation_count = 1;
if ($product->is_type('variable')) {
$variation_count = count($offer->get_children());
$variations = $product->get_available_variations();
}
while ($variation_count > 0) {
$variation_count--;
// If variable product, get product id from $variations array.
$offerID = $product->is_type('variable') ? $variations[$variation_count]['variation_id'] : $product->id;
// Prepare variation link.
$var_link = '';
if ($product->is_type('variable')) {
$variable_attribute = wc_get_product_variation_attributes($offerID);
$var_link = '?' . key($variable_attribute) . '=' . current($variable_attribute);
// This has to work but we need to think of a way to save the initial offer variable.
$offer = new WC_Product_Variation($offerID);
}
// NOTE: Below this point we start using $offer instead of $product.
$yml .= ' <offer id="' . $offerID . '" available="' . ($offer->is_in_stock() ? "true" : "false") . '">' . PHP_EOL;
$yml .= ' <url>' . get_permalink($offer->id) . $var_link . '</url>' . PHP_EOL;
// Price.
if ($offer->sale_price && $offer->sale_price < $offer->regular_price) {
$yml .= ' <price>' . $offer->sale_price . '</price>' . PHP_EOL;
$yml .= ' <oldprice>' . $offer->regular_price . '</oldprice>' . PHP_EOL;
} else {
$yml .= ' <price>' . $offer->regular_price . '</price>' . PHP_EOL;
}
$yml .= ' <currencyId>' . $currency . '</currencyId>' . PHP_EOL;
// Category.
// Not using $offerID, because variable products inherit category from parent.
$categories = get_the_terms($product->id, 'product_cat');
$category = array_shift($categories);
$yml .= ' <categoryId>' . $category->term_id . '</categoryId>' . PHP_EOL;
// Market category.
if (isset($this->settings['market_category']) && $this->settings['market_category'] != 'not_set') {
$market_category = wc_get_product_terms($offerID, 'pa_' . $this->settings['market_category'], array('fields' => 'names'));
if ($market_category) {
$yml .= ' <market_category>' . wp_strip_all_tags(array_shift($market_category)) . '</market_category>' . PHP_EOL;
}
}
// TODO: get all the images
$image = get_the_post_thumbnail_url(null, 'full');
//foreach ( $images as $image ):
if (strlen(utf8_decode($image)) <= 512) {
$yml .= ' <picture>' . esc_url($image) . '</picture>' . PHP_EOL;
}
//endforeach;
$yml .= ' <delivery>true</delivery>' . PHP_EOL;
$yml .= ' <name>' . $offer->get_title() . '</name>' . PHP_EOL;
// Vendor.
if (isset($this->settings['vendor']) && $this->settings['vendor'] != 'not_set') {
$vendor = wc_get_product_terms($offer->ID, 'pa_' . $this->settings['vendor'], array('fields' => 'names'));
if ($vendor) {
$yml .= ' <vendor>' . wp_strip_all_tags(array_shift($vendor)) . '</vendor>' . PHP_EOL;
}
}
// Vendor code.
if ($offer->sku) {
$yml .= ' <vendorCode>' . $offer->sku . '</vendorCode>' . PHP_EOL;
}
// Description.
if ($offer->post->post_content) {
$yml .= ' <description><![CDATA[' . html_entity_decode($offer->post->post_content, ENT_COMPAT, "UTF-8") . ']]></description>' . PHP_EOL;
}
// Sales notes.
if ($this->settings['sales_notes'] == 'yes' && $offer->post->post_excerpt) {
$yml .= ' <sales_notes>' . wp_strip_all_tags($offer->post->post_excerpt) . '</sales_notes>' . PHP_EOL;
}
$yml .= ' </offer>' . PHP_EOL;
}
}
return $yml;
}
示例4: array
_e('Stock', 'woothemes');
?>
</th>
</tr>
</thead>
<tbody>
<?php
$args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'meta_query' => array(array('key' => '_stock', 'value' => array('', false, null), 'compare' => 'NOT IN')));
$loop = new WP_Query($args);
while ($loop->have_posts()) {
$loop->the_post();
$product = new WC_Product_Variation($loop->post->ID);
?>
<tr>
<td><?php
echo $product->get_title();
?>
</td>
<td><?php
echo get_the_title($loop->post->post_parent);
?>
</td>
<td><?php
echo $product->sku;
?>
</td>
<td><?php
echo $product->stock;
?>
</td>
</tr>
示例5: explode
//.........这里部分代码省略.........
$product = wc_get_product($prod);
$id = $product->id;
$price_html = $product->get_price_html();
if (preg_match('/<ins>(.*?)<\\/ins>/', $price_html)) {
preg_match('/<ins>(.*?)<\\/ins>/', $price_html, $matches);
$price_html = $matches[1];
}
$price_html = strip_tags($price_html);
$price = $price_html;
$sku = $product->get_sku();
$title = get_the_title($product->id);
$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
$img = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'thumbnail');
$img = $img[0];
if (!empty($img)) {
$img = $img;
} else {
$img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
}
} elseif ('product' == $post_type && !empty($children)) {
$hide_product = 'true';
} elseif ('product_variation' == $post_type) {
$product = new WC_Product_Variation($prod);
$parent = wc_get_product($prod);
$id = $product->variation_id;
$price_html = $product->get_price_html();
if (preg_match('/<ins>(.*?)<\\/ins>/', $price_html)) {
preg_match('/<ins>(.*?)<\\/ins>/', $price_html, $matches);
$price_html = $matches[1];
}
$price_html = strip_tags($price_html);
$price = $price_html;
$sku = $product->get_sku();
$title = $product->get_title();
$attributes = $product->get_variation_attributes();
$img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
foreach ($attributes as $name => $value) {
$name = str_ireplace("attribute_", "", $name);
$terms = get_the_terms($product->id, $name);
foreach ($terms as $term) {
if (strtolower($term->name) == $value) {
$value = $term->name;
}
}
$attr_name = $name;
$attr_value = $value;
$attr_value = str_replace('-', ' ', $value);
if ($this->options['attribute_style'] === 'true') {
$title .= ' ' . $attr_value . ' ';
} else {
if (strstr($attr_name, 'pa_')) {
$atts = get_the_terms($parent->id, $attr_name);
$attr_name_clean = WC_Bulk_Order_Form_Compatibility::wc_attribute_label($attr_name);
} else {
$np = explode("-", str_replace("attribute_", "", $attr_name));
$attr_name_clean = ucwords(implode(" ", $np));
}
$attr_name_clean = str_replace("attribute_pa_", "", $attr_name_clean);
$attr_name_clean = str_replace("Attribute_pa_", "", $attr_name_clean);
$title .= " - " . $attr_name_clean . ": " . $attr_value;
}
$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
}
$parent_image = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'thumbnail');
$parent_image = $parent_image[0];
$img = wp_get_attachment_image_src(get_post_thumbnail_id($parent->id), 'thumbnail');