別のカテゴリの商品を購入すると、無料の商品 (色を選択できます) がもらえるサイトを作成しています。カートに追加をクリックすると、1 つのカテゴリ タイプを 1 つの無料製品にリダイレクトする方法はありますか? ただし、他のすべてのカテゴリはリダイレクトされません。
1 に答える
1
カートに追加された製品 ID に応じて、リダイレクトを追加できます (「added-to-cart」GET 変数を介して)。そして、そこからカテゴリ ID を取得します。
// Add redirect action
add_action( 'template_redirect', 'check_cart_product', 0 );
function check_cart_product(){
// get product ID, then category ID
$product_ID = $_GET['added-to-cart'];
$term_list = wp_get_post_terms($product_ID,'product_cat',array('fields'=>'ids'));
$cat_id = (int)$term_list[0];
// check if product is from specific category, then redirect
if($cat_id == 25)
wp_redirect(get_permalink(352));
}
于 2013-07-29T14:12:00.947 に答える