1 回答

TA貢獻(xiàn)1806條經(jīng)驗 獲得超5個贊
您可以創(chuàng)建要顯示“繼續(xù)購物”鏈接的類別數(shù)組,以及購物車中當(dāng)前所有類別的數(shù)組。然后您可以使用array_intersect()來查看兩個數(shù)組之間是否存在匹配。如果是,請顯示鏈接:
add_action( 'woocommerce_before_cart_table', 'woo_add_continue_shopping_button_to_cart_products' );
function woo_add_continue_shopping_button_to_cart_products() {
// Define categories which should show the keep shopping link
$keep_shopping = array( 'Music', 'Clothing' );
// Check categories in the cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$terms = get_the_terms( $cart_item['product_id'], 'product_cat' );
if ( !empty($terms) ) {
foreach ($terms as $key => $term) {
$order_cats[$term->term_id] = $term->name;
}
}
}
// Get array of category matches
$cat_matches = array_intersect( $keep_shopping, $order_cats );
if ( count( $cat_matches ) > 0 ) {
// 1 or more matches, show keep shopping link
printf( '<div class="woocommerce-message"><a href="%s" class="button">Continue Shopping →</a> Do you want more products?</div>', get_permalink( wc_get_page_id( 'shop' ) ) );
}
}
- 1 回答
- 0 關(guān)注
- 107 瀏覽
添加回答
舉報