function wb_public_display_html() { $wb_woocommerce = wb_woocommerce_data(); if ($wb_woocommerce) { if ($wb_woocommerce->cart) { ?> <div class="wb_display_widget_cart"> <div class="cart_list product_list_widget wb_cart_product wb_cart_front_end_wrapper" id="wb_cart_front_end_wrapper"> <?php $wb_data = wb_built_bag(); echo $wb_data; ?> </div> </div> <?php } } }
function wb_product_list($wb_call_option = NULL, $wb_all_option, $wb_template_name_part) { $wb_new_product_id = ''; if (isset($wb_call_option) && !empty($wb_call_option)) { if ($wb_call_option['add_cart'] == 'yes') { $wb_new_product_id = $wb_call_option['product_id']; } } $wb_woocommerce = wb_woocommerce_data(); if ($wb_woocommerce) { if ($wb_woocommerce->cart) { $wb_data = ''; $wb_product_list = ''; $wb_p_data = $wb_woocommerce->cart->get_cart(); $wb_products_data = array_reverse($wb_p_data); $wb_count_product = 0; $wb_top_product = ''; $wb_remove_class = ''; $wb_other_product = ''; $wb_reduce_quantity = ''; $wb_remove_product_link = ''; $wb_text_after_product_price = $wb_all_option[$wb_template_name_part . '_product_setting_wb_text_after_product_price']; $show_product_image = $wb_all_option[$wb_template_name_part . '_product_setting_show_product_image']; $wb_remove_button_icon = $wb_all_option[$wb_template_name_part . '_product_setting_wb_remove_button_icon']; $show_product_price = $wb_all_option[$wb_template_name_part . '_product_setting_show_product_price']; $wb_currency_symbol = get_woocommerce_currency_symbol(); $wb_product_list .= '<table>'; foreach ($wb_products_data as $cart_item_key => $cart_item) { $wb_count_product++; $_product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key); $product_id = apply_filters('woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key); if ($_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters('woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key)) { $wb_product_quantity = $cart_item['quantity']; $product_name = apply_filters('woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key); if (isset($wb_new_product_id) && !empty($wb_new_product_id) && $product_id == $wb_new_product_id) { $wb_other_product = $wb_data; $wb_data = ''; $wb_data .= '<tr ' . 'id="wb_cart_single_product_' . $wb_count_product . '" ' . 'class="wb_cart_single_product wb_cart_single_product_' . $wb_count_product . ' ' . $wb_remove_class . '" ' . '>'; } else { $wb_data .= '<tr ' . 'class="wb_cart_single_product wb_cart_single_product_' . $wb_count_product . '" ' . 'id="wb_cart_single_product_' . $wb_count_product . '"' . '>'; } if (has_post_thumbnail($product_id)) { $wb_product_image_url = wp_get_attachment_url(get_post_thumbnail_id($product_id)); } else { $wb_product_image_url = wc_placeholder_img_src(); } if ($show_product_image == 'yes') { $wb_data .= '<td class="wb_product_thumbnail">'; if (!$_product->is_visible()) { $wb_data .= '<img src="' . $wb_product_image_url . '" >'; } else { $wb_data .= '<a href="' . esc_url(get_permalink($product_id)) . '">'; $wb_data .= '<img src="' . $wb_product_image_url . '" >'; $wb_data .= '</a>'; } $wb_data .= '</td>'; } $wb_data .= '<td class="wb_product_detail"> <div class="wb_product_name">'; if (!$_product->is_visible()) { $wb_data .= __($product_name, 'woo-bag'); } else { $wb_data .= '<a href="' . esc_url(get_permalink($product_id)) . '">'; $wb_data .= __($product_name, 'woo-bag'); $wb_data .= '</a>'; } $wb_data .= '</div>'; $wb_data .= apply_filters('woocommerce_widget_cart_item_quantity', '<span class="quantity"><span class="wb_quantity_label">' . __('Quantity', 'woo-bag') . ': </span><span class="wb_total_quentity">' . __($wb_product_quantity, 'woo-bag') . '</span></span>', $cart_item, $cart_item_key); /** Product Price Start */ $product_regular_price = apply_filters('woocommerce_cart_item_price', $_product->regular_price, $cart_item, $cart_item_key); if ($_product->get_price() && $_product->is_on_sale() && isset($show_product_price) && $show_product_price == 'regular_sale') { $wb_sales_price = $_product->sale_price; $wb_data .= apply_filters('woocommerce_widget_cart_item_price', '<div class="price"><span class="wb_price_label">' . __('Price', 'woo-bag') . ':</span> ' . '<span class="wb_product_reqular_amount">' . $wb_currency_symbol . '' . __(number_format($product_regular_price, 2), 'woo-bag') . '' . '</span> ' . '<span class="wb_product_amount">' . $wb_currency_symbol . '' . __(number_format($wb_sales_price, 2), 'woo-bag') . ' <span class="wb_text_after_product_price">' . __($wb_text_after_product_price, 'woo-bag') . '</span></span>' . '</div>', $cart_item, $cart_item_key); } else { $wb_data .= apply_filters('woocommerce_widget_cart_item_price', '<div class="price"><span class="wb_price_label">' . __('Price', 'woo-bag') . ':</span> ' . '<span class="wb_product_amount">' . $wb_currency_symbol . '' . __(number_format($product_regular_price, 2), 'woo-bag') . '<span class="wb_text_after_product_price">' . __($wb_text_after_product_price, 'woo-bag') . '</span></span></div>', $cart_item, $cart_item_key); } if ($_product->get_price() && $_product->is_on_sale()) { $percentage = round(($_product->regular_price - $_product->sale_price) / $_product->regular_price * 100); $wb_data .= '<span class="wb_saving_percentage"> ' . sprintf(__('Save: %s', 'woo-bag'), $percentage . '%') . '</span>'; } if ($cart_item['line_tax'] == 0) { $wb_tax_per_product = __('0.00', 'woo-bag'); } else { $wb_tax_per_product = __($cart_item['line_tax'], 'woo-bag'); } $wb_data .= '<span class="wb_tax_per_item"> ' . __('Tax', 'woo-bag') . ': ' . $wb_currency_symbol . __($wb_tax_per_product, 'woo-bag') . ' </span>'; /** Product Price End */ /** Product Custom Attributes Start */ $wb_data .= '<div class="wb_custom_attributes">'; $wb_variable_data = wb_get_item_data($cart_item); if ($wb_variable_data) { foreach ($wb_variable_data as $data) { $wb_attribute_key = strtolower($data['key']); $wb_custom_attributes = $wb_all_option[$wb_template_name_part . '_product_setting_wb_custom_attributes_' . $wb_attribute_key]; if ($wb_custom_attributes) { $wb_data .= '<span class="wb_custom_single">' . __($data['key'], 'woo-bag') . ': ' . __($data['value'], 'woo-bag') . '</span>'; } } } $wb_data .= '</div>'; /** Product Custom Attributes End */ $wb_data .= '<div class="wb_single_product_id wb_hidden_fields" id="' . $product_id . '">' . $product_id . '</div>'; $wb_data .= '<div class="wb_single_product_tax wb_hidden_fields" id="' . $cart_item["line_tax"] . '"></div>'; $wb_data .= '</td>'; $wb_data .= '<td class="wb_remove_button">'; $wb_data .= '<p class="buttons wb_remove_product"> <span onclick="wb_remove_conform(\'wb_cart_single_product_' . $wb_count_product . '\');" id="' . $wb_woocommerce->cart->get_remove_url($cart_item_key) . '">'; if ($wb_remove_button_icon) { $wb_data .= '<i class="' . $wb_remove_button_icon . '"></i></span></span>'; } else { $wb_data .= '<i class="fa fa-times-circle"></i></span></span>'; } $wb_data .= '</p>'; $wb_data .= '</td>'; $wb_data .= '</tr>'; if (isset($wb_new_product_id) && !empty($wb_new_product_id) && $product_id == $wb_new_product_id) { $wb_top_product = $wb_data; $wb_data = $wb_other_product; } } $wb_count_product++; } $wb_product_list .= $wb_top_product . $wb_data; $wb_product_list .= '</table>'; } } if (isset($wb_call_option) && !empty($wb_call_option) && $wb_call_option['add_cart'] === 'yes') { $wb_data = array(); $wb_data['product_data'] = $wb_product_list; return $wb_data; } else { return $wb_product_list; } }
function wb_clear_cart() { $wb_woocommerce = wb_woocommerce_data(); if ($wb_woocommerce) { if ($wb_woocommerce->cart) { $wb_woocommerce->cart->empty_cart(); } } $wb_data = array(); $wb_full_cart = wb_built_bag(); $wb_data["command"] = "success"; $wb_data["product_data"] = $wb_full_cart; echo json_encode($wb_data); die; }