Use below Code to or Automatic Addition of Product along with Other. if you added one product and wanted to add one more with this product use following code for this.
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’];
if ( $_product->id == $product_id ){
$found = true;
}
//prasa
/* for conditional
$addon=95; $addon2=93;
if ( $_product->id ==$addon || $_product->id==$addon2)
{
$woocommerce->cart->add_to_cart( $product_id);
} */
//prasa
}
// if product not found, add it
if ( $found )
$woocommerce->cart->add_to_cart( $free_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

