根据在 Woo 中添加特定产品挂钩功能
Hook a function based on adding a particular product in Woo
我需要根据添加到 Woocommerce 购物车的特定产品创建操作挂钩:
当 PRODUCT-#123 添加到购物车时,然后 doThisFunction();
知道怎么做吗?
将以下代码添加到您主题的 functions.php 文件
add_action( 'woocommerce_add_to_cart', 'custom_add_to_cart', 10, 2 );
function custom_add_to_cart( $cart_item_key, $product_id ) {
// replace 123 with a valid product ID
if( 123 == $product_id ) {
//call the desired function
}
}
我需要根据添加到 Woocommerce 购物车的特定产品创建操作挂钩:
当 PRODUCT-#123 添加到购物车时,然后 doThisFunction();
知道怎么做吗?
将以下代码添加到您主题的 functions.php 文件
add_action( 'woocommerce_add_to_cart', 'custom_add_to_cart', 10, 2 );
function custom_add_to_cart( $cart_item_key, $product_id ) {
// replace 123 with a valid product ID
if( 123 == $product_id ) {
//call the desired function
}
}