我试图在产品缺货时显示一个块或DIV,但条件似乎不起作用
add_action( 'woocommerce_get_availability', 'display_welcome', 10);
function display_welcome() {
global $_product;
if ( ! $_product->is_in_stock() ) {
?>
<style>
#hello {display:block }
</style>
<?
}
}
HTML
<div id="hello">Try this product instead</div>
答案 0 :(得分:0)
add_action('woocommerce_get_availability', 'display_welcome', 10, 2);
function display_welcome($availability_class, $_product) {
if ($availability_class['availability'] == 'Out of stock') {
$availability_class['class'] = $availability_class['class'] . ' my-customclass';
add_action('woocommerce_single_product_summary', 'hooks_add_div', 33);
function hooks_add_div() {
echo '<div id="helllo">mujeebu rahman</div>';
}
}
}