__('added successfully.','xoo-cp-domain'), 'updated' => __('updated successfully.','xoo-cp-domain'), 'removed' => __('removed from cart.','xoo-cp-domain') ); wp_localize_script('xoo-cp-js','xoo_cp_localize',array( 'adminurl' => admin_url().'admin-ajax.php', 'enshop' => $xoo_cp_gl_atces_value, 'xcp_text' => json_encode($xoo_cp_js_text) )); } add_action('wp_enqueue_scripts','xoo_cp_enqueue_scripts',500); //Popup HTML function xoo_cp_popup(){ global $woocommerce; $cart_url = $woocommerce->cart->get_cart_url(); $checkout_url = $woocommerce->cart->get_checkout_url(); ?>
cart->add_to_cart($product_id,$quantity,$variation_id,$attribute_values ); } elseif($variation_id === 0){ $cart_success = $woocommerce->cart->add_to_cart($product_id,$quantity); } //Successfully added to cart. if($cart_success){ $cart_item_key = $cart_success; $cart_data = $woocommerce->cart->get_cart(); $cart_item_data = $cart_data[$cart_item_key]; $item_cart_qty = $cart_item_data['quantity']; if($variation_id){ $product = new WC_product_variation($variation_id); $attributes = $product->get_formatted_variation_attributes(); } else{ $product = new WC_product($product_id); } $product_title = $product->post->post_title; $product_price = $product->get_price(); $product_image = $product->get_image('shop_thumbnail'); $product_total = $cart_item_data['line_total']; $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; if(!$xoo_cp_gl_qtyen_value){ $disabled = 'disabled'; } else{ $disabled = ''; } $html .= ''; $html .= ''; $html .= '
'.$product_image.''.$product_title.''; if(isset($attributes)){ $html .= '
'.$attributes.'
'; } $html .= '
'.get_woocommerce_currency_symbol().$product_price.''; $html .= ''; $html .= ''; $html .= ''; $html .= '
'; $html .= '
'.__('Total','xoo-cp-domain').': '.get_woocommerce_currency_symbol().$product_total.'
'; $ajax_fragm = xoo_cp_ajax_fragments(); wp_send_json(array('pname' => $product_title , 'cp_html' => "$html" , 'ajax_fragm' => $ajax_fragm)); } else{ if(wc_notice_count('error') > 0){ echo wc_print_notices(); } } die(); } add_action('wp_ajax_xoo_cp_cart_ajax','xoo_cp_cart_ajax'); add_action('wp_ajax_nopriv_xoo_cp_cart_ajax','xoo_cp_cart_ajax'); //Ajax change in cart function xoo_cp_change_ajax(){ global $woocommerce; $cart_key = sanitize_text_field($_POST['cart_key']); $new_qty = (int) $_POST['new_qty']; $pid = (int) $_POST['pid']; $cart_data = $woocommerce->cart->get_cart(); $cart_item_data = $cart_data[$cart_key]; $item_cart_qty = $cart_item_data['quantity']; if($item_cart_qty > $new_qty){ $cart_success = $woocommerce->cart->set_quantity($cart_key,$new_qty); } else{ $additional_qty = $new_qty - $item_cart_qty; $variation_id = $cart_item_data['variation_id']; if($variation_id){ $product_id = $cart_item_data['product_id']; $attribute_values = $cart_item_data['variation']; $cart_success = $woocommerce->cart->add_to_cart($product_id,$additional_qty,$variation_id,$attribute_values ); } else{ $product_id = $pid; $cart_success = $woocommerce->cart->add_to_cart($product_id,$additional_qty); } } if($cart_success && $new_qty != 0){ $new_cart_data = $woocommerce->cart->get_cart(); $new_cart_item_data = $new_cart_data[$cart_key]; $ptotal = get_woocommerce_currency_symbol().$new_cart_item_data['line_total']; $ajax_fragm = xoo_cp_ajax_fragments(); $data = array('ptotal' => $ptotal ,'ajax_fragm' => $ajax_fragm); wp_send_json($data); } else{ if(wc_notice_count('error') > 0){ echo wc_print_notices(); } } die(); } add_action('wp_ajax_xoo_cp_change_ajax','xoo_cp_change_ajax'); add_action('wp_ajax_nopriv_xoo_cp_change_ajax','xoo_cp_change_ajax'); //Get Ajax refreshed fragments function xoo_cp_ajax_fragments(){ // Get mini cart ob_start(); woocommerce_mini_cart(); $mini_cart = ob_get_clean(); // Fragments and mini cart are returned $data = array( 'fragments' => apply_filters( 'woocommerce_add_to_cart_fragments', array( 'div.widget_shopping_cart_content' => '
' . $mini_cart . '
' ) ), 'cart_hash' => apply_filters( 'woocommerce_add_to_cart_hash', WC()->cart->get_cart_for_session() ? md5( json_encode( WC()->cart->get_cart_for_session() ) ) : '', WC()->cart->get_cart_for_session() ) ); return $data; } //Options Styles function xoo_cp_styles(){ global $xoo_cp_sy_pw_value,$xoo_cp_sy_imgw_value,$xoo_cp_sy_btnbg_value,$xoo_cp_sy_btnc_value,$xoo_cp_sy_btns_value,$xoo_cp_sy_btnbr_value,$xoo_cp_sy_tbc_value,$xoo_cp_sy_tbs_value,$xoo_cp_gl_ibtne_value,$xoo_cp_gl_vcbtne_value,$xoo_cp_gl_chbtne_value,$xoo_cp_gl_qtyen_value; $style = ''; if(!$xoo_cp_gl_ibtne_value || !$xoo_cp_gl_qtyen_value){ $style .= '.xcp-chng{ display: none; }'; } if(!$xoo_cp_gl_vcbtne_value){ $style .= 'a.xoo-cp-btn-vc{ display: none; }'; } if(!$xoo_cp_gl_chbtne_value){ $style .= 'a.xoo-cp-btn-ch{ display: none; }'; } echo ""; } add_action('wp_head','xoo_cp_styles');