اضافة منتج الى السلة اتوماتكيا عند الدخول الى صفحة المنتج في متجر ووكومرس Automatically add product to cart on visit product page

اضافة منتج الى السلة اتوماتكيا عند الدخول الى صفحة المنتج في متجر ووكومرس Automatically add product to cart on visit product page

function action_woocommerce_single_product_summary() {
// Get the global product object
global $product;

// Quantity for add to cart
$quantity = 1;

// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// Get ID
$product_id = $product->get_id();

// WC Cart
if ( WC()->cart ) {
// Get cart
$cart = WC()->cart;

// Cart NOT empty
if ( sizeof( $cart->get_cart() ) > 0 ) {
// Cart id
$product_cart_id = $cart->generate_cart_id( $product_id );

// Find product in cart
$in_cart = $cart->find_product_in_cart( $product_cart_id );

// NOT in cart
if ( ! $in_cart ) {
$cart->add_to_cart( $product_id, $quantity );
}
} else {
$cart->add_to_cart( $product_id, $quantity );
}
}
}
}
add_action( 'woocommerce_single_product_summary', 'action_woocommerce_single_product_summary', 10, 0 );
خصم على استضافة Hostinger لا تضيع الفرصة.اطلب الان
🔥 عرض خاص: خصم 79% على استضافة Hostinger لفترة محدودة! 🚀 احصل على العرض الآن
Scroll to Top