Php 显示WooCommerce存档中产品的缺货状态,特定元数据除外
我使用以下内容在WooCommerce归档页面上显示库存状态:Php 显示WooCommerce存档中产品的缺货状态,特定元数据除外,php,wordpress,woocommerce,metadata,product,Php,Wordpress,Woocommerce,Metadata,Product,我使用以下内容在WooCommerce归档页面上显示库存状态: <?php //add action give it the name of our function to run add_action( 'woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25 ); //create our function function wcs_stock_text_shop_page() { //re
<?php
//add action give it the name of our function to run
add_action( 'woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25 );
//create our function
function wcs_stock_text_shop_page() {
//returns an array with 2 items availability and class for CSS
global $product;
$availability = $product->get_availability();
//check if availability in the array = string 'Out of Stock'
//if so display on page.//if you want to display the 'in stock' messages as well just leave out this, == 'Out of stock'
if ( $availability['availability'] == 'Out of stock') {
echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] );
}
}
您可以使用产品id在POSTETA表中检查元数据,如果存在,则退出函数
<?php
//add action give it the name of our function to run
add_action( 'woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25 );
//create our function
function wcs_stock_text_shop_page() {
//returns an array with 2 items availability and class for CSS
global $product;
$meta = get_post_meta($product->get_ID(), '_ywpo_preorder', true);
if($meta)
{
return;
}
$availability = $product->get_availability();
//check if availability in the array = string 'Out of Stock'
//if so display on page.//if you want to display the 'in stock' messages as well just leave out this, == 'Out of stock'
if ( $availability['availability'] == 'Out of stock') {
echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] );
}
}
您可以使用产品id在POSTETA表中检查元数据,如果存在,则退出函数
<?php
//add action give it the name of our function to run
add_action( 'woocommerce_after_shop_loop_item_title', 'wcs_stock_text_shop_page', 25 );
//create our function
function wcs_stock_text_shop_page() {
//returns an array with 2 items availability and class for CSS
global $product;
$meta = get_post_meta($product->get_ID(), '_ywpo_preorder', true);
if($meta)
{
return;
}
$availability = $product->get_availability();
//check if availability in the array = string 'Out of Stock'
//if so display on page.//if you want to display the 'in stock' messages as well just leave out this, == 'Out of stock'
if ( $availability['availability'] == 'Out of stock') {
echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] );
}
}