概要
woocommerce_continue_shopping_redirect
フィルタは、WooCommerceのショッピングカートやチェックアウトプロセスで、ユーザーが「買い物を続ける」ボタンをクリックしたときのリダイレクト先URLを変更するために使用されます。このフィルタを利用することで、カスタムページや特定のカテゴリーページにリダイレクトすることができ、ユーザー体験を向上させることができます。
このフィルタは、以下のような機能を実装する際によく使われます:
- 特定のカテゴリーへのリダイレクト
- カスタムランディングページへの移動
- プロモーション用ページの作成
- 特定の製品群へのナビゲーション
- ユーザーのインタラクションを促すカスタムアクション
- 特別なオファーやキャンペーンの案内ページへの誘導
構文
add_filter('woocommerce_continue_shopping_redirect', 'custom_continue_shopping_redirect');
function custom_continue_shopping_redirect($redirect_url) {
// カスタムURLを返す
return 'https://example.com/custom-page'; // カスタムページURL
}
パラメータ
$redirect_url
: デフォルトのリダイレクト先URL。これに新しいURLを設定できます。
戻り値
- 新しいリダイレクト先のURL(文字列)。
使用可能なバージョン
- WooCommerce:3.0以上
- WordPress:4.5以上
この関数のアクションでの使用可能性
アクション名 | 使用例 |
---|---|
mu_plugin_loaded | |
registered_post_type | |
plugins_loaded | |
wp_roles_init | |
setup_theme | |
after_setup_theme | |
set_current_user | |
init | |
register_sidebar | |
wp_loaded | |
send_headers | |
parse_query | |
pre_get_posts | |
wp | |
template_redirect | |
get_header | |
wp_head |
サンプルコード
サンプル1: カスタムカテゴリーページへのリダイレクト
add_filter('woocommerce_continue_shopping_redirect', 'redirect_to_category_page');
function redirect_to_category_page($redirect_url) {
return get_term_link('my-category', 'product_cat'); // カスタムカテゴリーのURL
}
このサンプルコードは、「買い物を続ける」ボタンをクリックしたときに特定の製品カテゴリーページにリダイレクトします。
サンプル2: 特別オファーページへのリダイレクト
add_filter('woocommerce_continue_shopping_redirect', 'redirect_to_special_offer');
function redirect_to_special_offer($redirect_url) {
return 'https://example.com/special-offer'; // 特別オファー用ページURL
}
このサンプルは、ユーザーを特別オファーページに誘導します。
サンプル3: サポートページへのリダイレクト
add_filter('woocommerce_continue_shopping_redirect', 'redirect_to_support_page');
function redirect_to_support_page($redirect_url) {
return 'https://example.com/support'; // サポートセンターへのURL
}
このコードは、サポートページへリダイレクトします。
サンプル4: プロモーション用ページへのリダイレクト
add_filter('woocommerce_continue_shopping_redirect', 'redirect_to_promotion_page');
function redirect_to_promotion_page($redirect_url) {
return 'https://example.com/promotion'; // プロモーションページのURL
}
このサンプルでは、プロモーション用ページにリダイレクトします。
サンプル5: スペシャルセールページへのリダイレクト
add_filter('woocommerce_continue_shopping_redirect', 'redirect_to_special_sale');
function redirect_to_special_sale($redirect_url) {
return 'https://example.com/special-sale'; // スペシャルセールページのURL
}
このコードは、スペシャルセールページへリダイレクトします。