Viewing 2 replies - 1 through 2 (of 2 total)
  • That code you supplied doesn’t appear to work for me.

    You could try this snippet instead:

    add_filter( 'woocommerce_add_to_cart_validation', function ( $passed, $product_id, $quantity ) {
    if ( isset( $_GET['add-to-cart'] ) ) {
    wc_add_notice( __( 'Adding to cart via URL is not allowed.', 'your-text-domain' ), 'error' );
    return false;
    }
    return $passed;
    }, 10, 3 );

    It hooks onto the add to cart validation filter and decides if it should be added to the cart or now. If the “add-to-cart” parameter is set in the URL then it’s not going to add the product to the cart.

    You can edit the error message, as it’s currently set to “Adding to cart via URL is not allowed.”.

    Thread Starter Group Of Oceninfo

    (@princebhalani143)

    @robinrsa Awesome, thanks for your reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.