Last active
April 11, 2024 07:46
-
-
Save Acephalia/d8020ac7fffa569d8aa77d74c572baae to your computer and use it in GitHub Desktop.
Woocommerce add to cart for product thumbnail link
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
//Don't use this it is a bad idea. This code replaces all acrhcive and shop page thumbnail links to work as add to cart urls. When clicked the item will be added to cart instead of opening the single product page. Works only for simple products (obviously). | |
function wc_custom_shop_thumbnail_link( $link, $product ) { | |
if ( $product->is_type( 'simple' ) && ( is_shop() || is_product_category() || is_product_tag() ) ) { | |
$link = '?add-to-cart='. $product->get_id(); | |
} | |
return $link; | |
} | |
add_filter( 'woocommerce_loop_product_link', 'wc_custom_shop_thumbnail_link', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reddit request : https://www.reddit.com/r/woocommerce/comments/1bzqg9q/directly_adding_product_to_cart_when_clicking_on/