• Resolved MagineM

    (@maginem)


    Hi,

    I’ve got an online catalog setup to only display pricing when logged in. The theme however does not show the Ajax Add To Cart button on archive pages. So if I add the script below to functions.php, the button shows.

    add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart' );

    However, I need this script to only take effect when the user is logged in. Currently all users can see the button.
    Have tried to get an if statement going but my PHP coding skills aren’t the best.

    Any help appreciated.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    if ( is_user_logged_in() ) {
    add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_add_to_cart' );
    }
    Thread Starter MagineM

    (@maginem)

    Hi Mike,

    Yay! Thank you! Works ??

    Where to add this statement

    if ( is_user_logged_in() ) {
    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_add_to_cart’ );
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add To Cart only if logged in’ is closed to new replies.