function rd_add_cart_button() { global $product, $rd_config; if ($product->product_type == 'bundle') { $product = new WC_Product_Bundle($product->id); } $extraClass = ""; ob_start(); woocommerce_template_loop_add_to_cart(); $output = ob_get_clean(); if (!empty($output)) { $pos = strpos($output, ">"); if ($pos !== false) { $output = substr_replace($output, "> ", $pos, strlen(1)); } } if ($product->product_type == 'variable' && empty($output)) { $output = '<a class="add_to_cart_button button product_type_variable" href="' . get_permalink($product->id) . '"> ' . __("Select options", "rd_framework") . '</a>'; } if (in_array($product->product_type, array('subscription', 'simple', 'bundle'))) { $output .= '<a class="button show_details_button" href="' . get_permalink($product->id) . '"> ' . __("Show Details", "rd_framework") . '</a>'; } if (!$product->is_in_stock()) { $output = '<a href="' . get_permalink() . '" rel="nofollow" class="button add_to_cart_button more_info_button out_stock_button"> ' . __("Out of Stock", "rd_framework") . '</a>'; } else { $extraClass = "single_button"; } if (empty($extraClass)) { $output .= " <span class='button-mini-delimiter'></span>"; } if ($output && !post_password_required()) { echo "<div class='custom_cart_button {$extraClass}'>{$output}</div>"; } }
/** * Activate single course if already purchases * @return void */ public function activate_purchased_single_course() { global $post, $current_user; if (WooThemes_Sensei_Utils::sensei_is_woocommerce_activated()) { if (!is_user_logged_in()) { return; } if (!isset($post->ID)) { return; } $user_id = $current_user->ID; $course_id = $post->ID; $course_product_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true); if (!$course_product_id) { return; } $user_course_status = WooThemes_Sensei_Utils::user_course_status(intval($course_id), $user_id); // Ignore course if already completed if (WooThemes_Sensei_Utils::user_completed_course($user_course_status)) { return; } // Ignore course if already started if ($user_course_status) { return; } // Get all user's orders $order_args = array('post_type' => 'shop_order', 'posts_per_page' => -1, 'post_status' => array('wc-processing', 'wc-completed'), 'meta_query' => array(array('key' => '_customer_user', 'value' => $user_id)), 'fields' => 'ids'); $orders = get_posts($order_args); foreach ($orders as $order_post_id) { // Get course product IDs from order $order = new WC_Order($order_post_id); $items = $order->get_items(); foreach ($items as $item) { $product = wc_get_product($item['product_id']); // handle product bundles if ($product->is_type('bundle')) { $bundled_product = new WC_Product_Bundle($product->id); $bundled_items = $bundled_product->get_bundled_items(); foreach ($bundled_items as $item) { if ($item->product_id == $course_product_id) { WooThemes_Sensei_Utils::user_start_course($user_id, $course_id); return; } } } else { // handle regular products if ($item['product_id'] == $course_product_id) { WooThemes_Sensei_Utils::user_start_course($user_id, $course_id); return; } } } } } }
/** * Filters result of get_price() **/ function woo_bundles_get_price($price, $product) { if ($product->is_type('bundle') && !isset($product->bundled_item_ids)) { $product = new WC_Product_Bundle($product->id); return $product->get_price(); } return $price; }
/** * When a bundle is static-priced, the price of all bundled items is set to 0. * When the shipping mode is set to "bundled", all bundled items are marked as virtual when they are added to the cart. * Otherwise, the container itself is a virtual product in the first place. * * @param array $cart_item * @param WC_Product_Bundle $bundle * @return array */ private function set_bundled_cart_item($cart_item, $bundle) { $bundled_item_id = $cart_item['bundled_item_id']; $per_product_pricing = $bundle->is_priced_per_product(); $per_product_shipping = $bundle->is_shipped_per_product(); if (!$per_product_pricing) { $cart_item['data']->price = 0; if (isset($cart_item['data']->subscription_sign_up_fee)) { $cart_item['data']->subscription_sign_up_fee = 0; } } else { $discount = $cart_item['stamp'][$cart_item['bundled_item_id']]['discount']; if (!empty($discount) || has_filter('woocommerce_bundle_is_composited')) { $bundled_item = $bundle->get_bundled_item($bundled_item_id); $bundled_item->add_price_filters($bundled_item); $cart_item['data']->price = $cart_item['data']->get_price(); unset($cart_item['data']->bundled_item); $bundled_item->remove_price_filters(); } } if ($cart_item['data']->needs_shipping()) { if (false === apply_filters('woocommerce_bundled_item_shipped_individually', $per_product_shipping, $cart_item['data'], $bundled_item_id, $bundle)) { if (apply_filters('woocommerce_bundled_item_has_bundled_weight', false, $cart_item['data'], $bundled_item_id, $bundle)) { $cart_item['data']->bundled_weight = $cart_item['data']->get_weight(); } $cart_item['data']->bundled_value = $cart_item['data']->price; $cart_item['data']->virtual = 'yes'; } } return apply_filters('woocommerce_bundled_cart_item', $cart_item, $bundle); }