我目前在WordPress网站上有一些功能属于某个woocommerce类别,并在产品属于此类别时更改“添加到购物车”按钮链接。一切正常,并且已经运行了几年。
我们第一次需要将此功能应用于两个不同的类别。这似乎是一个不常发生的实例,但是,我需要找出解决方案。
我需要If语句为if或if语句,并且我尝试过的所有操作都破坏了我的网站。
function so_43372512_maybe_show_auction_link(){
if( has_term( '12917', 'product_cat' ) ) {
echo ' <style type="text/css">
.woocommerce div.product form.cart, .woocommerce div.product p.cart {
display:none ; }
.woocommerce div.product p.price, .woocommerce div.product span.price {
display:none ; }
.woocommerce div.product p.stock {
display:none ; }
.product_meta {
margin-top:20px;
}
</style>';
echo '<p>Click This Button To View The Lot </p>';
global $product;
$skusearch = $product->get_sku();
echo '<a id="auction" style="font-size:100%;color:#fff;padding:.618em 1em;border-radius:3px;background-color:#ed1c24;font-weight:700;" href="https://www.boggsequipment.com/auctions" target="blank">' . __ ( 'On Auction Now!', 'your-plugin' ) . '</a>';
}
}
add_action( 'woocommerce_single_product_summary',
'so_43372512_maybe_show_auction_link', 35 );
// Remove the price on archive pages (like shop) for 'auction' product category
add_action('woocommerce_after_shop_loop_item_title', 'remove_price_from_archives', 9 );
function remove_price_from_archives(){
global $product, $post;
// Only for 'auction' product category
if ( has_term( '12917', 'product_cat' ) )
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
}
// Remove the displayed price and add-to-cart button on archive page for 'auction' product category
add_action( 'woocommerce_after_shop_loop_item', 'remove_the_displayed_price_from_variable_products', 9 );
function remove_the_displayed_price_from_variable_products() {
global $product, $post;
// Only for 'auction' product category
if ( has_term( '12917', 'product_cat' ) ){
// remove product price
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
// Add your custom "On Auction Now!" button
add_action( 'woocommerce_after_shop_loop_item', 'replace_add_to_cart_by_auction', 30 );
}
}
// This function displays your custom button replacement in archive pages
function replace_add_to_cart_by_auction(){
global $product;
$skusearch = $product->get_sku();
$style = 'style="font-size:70%;color:#fff;padding:.7em 1em;border-radius:3px;background-color:#ed1c24;font-weight:700;float:right;"';
$href = 'href="https://www.boggsequipment.com/auctions"';
echo '<a '.$href.' id="auction" '.$style.' target="blank">' . __ ( 'On Auction Now!', 'your-plugin' ) . '</a>';
}
// Replace the displayed price and add-to-cart button on archive page for 'auction' product category
add_action( 'woocommerce_after_shop_loop_item', 'readd_the_displayed_price_from_variable_products', 9 );
function readd_the_displayed_price_from_variable_products() {
global $product, $post;
// Only for non 'auction' product category
if ( ! has_term( '12917', 'product_cat' ) ){
// replace product price
remove_action( 'woocommerce_after_shop_loop_item', 'replace_add_to_cart_by_auction', 30 );
// Add your custom "On Auction Now!" button
add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
//replace product price properly
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
}
}
我需要的是'if(!has_term('12917','product_cat'))',使其包含两个不同的产品类别。例如产品类别“ 12917”或“ 12910”。任何帮助将不胜感激。
答案 0 :(得分:1)
if ( ! has_term( array('12917','12910'), 'product_cat' ) )
希望获得帮助。