Created
March 13, 2020 01:16
-
-
Save cocodrino/d4d891f236ed625d7dc78a146dfe5196 to your computer and use it in GitHub Desktop.
wordpress and woocommerce hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//=======LOGIN LOGOUT IN MENU | |
add_filter( 'wp_nav_menu_items', 'ia_custom_menu_item', 10, 2 ); | |
function ia_custom_menu_item ( $items, $args ) { | |
//var_dump($args); | |
if (is_user_logged_in()) { | |
$items .= '<li id="menu-item-logout" class="menu-item menu-item-type-custom menu-item-object-custom aiv_sign_button"><a href="/mi-cuenta/salir/">Salir</a></li>'; | |
} else { | |
$items .= '<li id="menu-item-login" class="menu-item menu-item-type-custom menu-item-object-custom aiv_sign_button"><a href="/mi-cuenta/">Ingreso | Registro</a></li>'; | |
} | |
return $items; | |
} | |
//====LOGIN/LOGOUT IN MENU | |
//==== REDIRECT TO CART AFTER REGISTRATION IF CONTAINS ITEM | |
function iconic_register_redirect( $redirect ) { | |
if (sizeof( WC()->cart->get_cart() ) > 0 ) { | |
return wc_get_page_permalink( 'checkout' ); | |
// return wp_redirect('/finalizar-compra/'); | |
} | |
} | |
add_filter( 'woocommerce_registration_redirect', 'iconic_register_redirect' ); | |
//==== REDIRECT TO CART AFTER REGISTRATION IF CONTAINS ITEM | |
//==== REDIRECT USER FROM CHECKOUT TO REGISTRATION WHEN THEY ARE NOT SIGN IN | |
add_action( 'template_redirect', 'checkout_redirect_non_logged_to_login_access'); | |
function checkout_redirect_non_logged_to_login_access() { | |
// Here the conditions (woocommerce checkout page and unlogged user) | |
if( is_checkout() && !is_user_logged_in()){ | |
// Redirecting to your custom login area | |
wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) ); | |
// always use exit after wp_redirect() function. | |
exit; | |
} | |
} | |
//==== REDIRECT USER FROM CHECKOUT TO REGISTRATION WHEN THEY ARE NOT SIGN IN | |
//=====REDIRECT TO CART AFTER LOGIN IF THEY'VE ITEMS IN IT | |
function login_redirect( $redirect ) { | |
if (sizeof( WC()->cart->get_cart() ) > 0 ) { | |
return wc_get_page_permalink( 'checkout' ); | |
// return wp_redirect('/finalizar-compra/'); | |
} | |
} | |
add_filter( 'woocommerce_login_redirect', 'login_redirect' ); | |
//=====REDIRECT TO CART AFTER LOGIN IF THEY'VE ITEMS IN IT |
Author
cocodrino
commented
Mar 21, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment