![](/img/trans.png)
[英]Cart bulk quantity discount for specific product tag IDs in WooCommerce
[英]Target specific product IDs on WooCommerce cart displayed quantity
我正在使用此代碼使產品在購物車中顯示框,但我只想讓它在某些產品上顯示。 我怎樣才能輸入產品ID?
function cw_change_product_quantity_display( $quantity ) {
$quantity .= ' Caja (s)';
return $quantity;
}
add_filter( 'woocommerce_get_quantity_html', 'cw_change_product_quantity_display' );
add_filter( 'woocommerce_cart_item_quantity', 'cw_change_product_quantity_display' );
woocommerce_get_quantity_html 鈎子在woocommerce_get_quantity_html
內核中沒有定義,所以可能是第三方插件、您的主題或您自己添加的自定義鈎子……
現在對於鈎子woocommerce_cart_item_quantity
,您的代碼中缺少 2 個額外的可選 arguments ,這將允許您定位產品 ID,例如:
add_filter( 'woocommerce_cart_item_quantity', 'change_cart_item_displayed_quantity', 10, 3 );
function change_cart_item_displayed_quantity( $product_quantity, $cart_item_key, $cart_item ) {
// Here define your product ID(s) in the array
$product_ids = array( 37, 53 );
if( array_intersect( [ $cart_item['product_id'], $cart_item['variation_id'] ], $product_ids ) ) {
$product_quantity .= __(' Caja (s)');
}
return $product_quantity;
}
它應該僅適用於某些已定義的產品 ID。
但是由於 $product 數量是一個輸入數字字段,您的自定義文本將顯示在此數量字段之后,這很奇怪。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.