How to Add Product to Cart When Visiting a Specific Page using Custom Code in WooCommerce Wordpress

preview_player
Показать описание
In this woocommerce tutorial for beginners you will learn how to add product in cart automatically when user visit a specific page in our wordpress website. So we will add custom php code in wp code plugin. So in code you will add product id and page id according to your requirement.

* Find Code in Top Pinned Comment Section.

#woocommerce #product #cart #shop #wordpress #wordpresstutorial #webtaskwithhassan #hassangilani
Рекомендации по теме
Комментарии
Автор

Use this code:

add_action( 'wp', );
function {
// product ID to add to cart
$product_id = 215;
// page ID to target
if ( is_page( 41 ) ) {
WC()->cart->empty_cart();
WC()->cart->add_to_cart( $product_id );
}
}

WebTaskWithHassan
Автор

Find Code in Top Pinned Comment Section??

M.Junaid-kn