本文整理汇总了PHP中WC_Product_Variation::is_in_stock方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variation::is_in_stock方法的具体用法?PHP WC_Product_Variation::is_in_stock怎么用?PHP WC_Product_Variation::is_in_stock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Product_Variation
的用法示例。
在下文中一共展示了WC_Product_Variation::is_in_stock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
<td>
<?php
if ($field_data) {
?>
<input
data-manage-stock="<?php
echo $managing_stock;
?>
"
data-purchasable="<?php
echo $variation->is_purchasable() ? '1' : '0';
?>
"
data-instock="<?php
echo $variation->is_in_stock() ? '1' : '0';
?>
"
data-backorders="<?php
echo $variation->backorders_allowed() ? '1' : '0';
?>
"
data-max="<?php
echo $variation->get_stock_quantity();
?>
"
data-price="<?php
echo $variation->get_price();
?>
"
data-vmsg="<?php
示例2: 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;
}