Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add_product_to_cart() {
- if (!is_admin()) {
- global $woocommerce;
- $items = $woocommerce->cart->get_cart();
- $live_product_ids = array(10305, 10302, 10300, 10303, 10301);
- $live_upsell_id = 10311;
- $suff_found = false;
- $upsell_found = false;
- $coupon_code = 'nutreincesufficiencyquiznakedcalories';
- //check if nut suff is already in cart
- if (sizeof($items) > 0) {
- foreach ($items as $cart_item_key => $values) {
- $_product = $values['data'];
- if (in_array($_product->id, $live_product_ids))
- $suff_found = true;
- if ($_product->id == $live_upsell_id)
- $upsell_found = true;
- }
- // if upsell product not found, add it
- if ($suff_found) {
- if (!$upsell_found)
- $woocommerce->cart->add_to_cart($live_upsell_id);
- if (!$woocommerce->cart->has_discount($coupon_code))
- $woocommerce->cart->add_discount($coupon_code);
- }
- }
- }
- }
- add_action('wp_loaded', 'add_product_to_cart');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement