Last active
May 10, 2020 10:38
-
-
Save Oscar-Abad-Folgueira/fe509b6e244716c8f2cf3263ad484b6f to your computer and use it in GitHub Desktop.
Añadir un producto al carrito de Woocommerce automaticamente con código
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 | |
/** | |
* @snippet Añadir un producto al carrito de Woocommerce automaticamente con código | |
* @author Oscar Abad Folgueira | |
* @author_url https://www.oscarabadfolgueira.com | |
* @snippet_url https://www.oscarabadfolgueira.com/anadir-un-producto-al-carrito-de-woocommerce-automaticamente-mediante-codigo/ | |
*/ | |
add_action( 'template_redirect', 'add_product_to_cart_automatically' ); | |
function add_product_to_cart_automatically() { | |
$product_id = 80; | |
if ( WC()->cart->get_cart_contents_count() == 0 ) { | |
WC()->cart->add_to_cart( $product_id ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment