Hello friends. i was testing to add the code for attached products.
Ex Product A if added automatically Products B will add
and Ex: If Product C is adding then it will check Product A is added or Not.
Here is simple script i have written to use in wordpress wocommerce.
add_action( ‘init’, ‘add_product_to_cart’ );
function add_product_to_cart()
{
if ( ! is_admin() )
{
global $woocommerce;
$product_id = 187; //Your product ID here
$free_product_id = 190; //Free product ID here
$found = false;
//check if product already in cart
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 )
{
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values )
{
$_product = $values[‘data’];
$found=true;
}
if($found)
{
if ( $_product->id == $product_id )
{
//$found = true;
$woocommerce->cart->add_to_cart( $free_product_id );}
else
{
$addon=95; $addon2=93;
if ( $_product->id ==$addon || $_product->id==$addon2)
{
$woocommerce->cart->add_to_cart( $product_id);
}
}
}
}}
}
Make an Enquiry
Categories
- Algorithm Update
- Articles Submission
- Canonicalization urls
- Dedicated Web Server
- Digital Marketing
- Frameworks
- Google Adsense
- Google Webmaster
- HTML
- Industrial Training projects for MCA/Engineering
- internet Marketing
- Job Openings
- Joomla Development
- MCA Live Projects
- MLM Software
- Newspaper Theme 8.5
- Notices
- Others
- Pay Per Click Advertising
- Paypal Integration
- PHP Development
- PHP MySQL
- PHP Professional Training
- Related Posts
- Search Engine Optimization
- Social Bookmarking
- Social Media Marketing
- Software Testing
- W3cValidation
- Wordpress

