css
2 years ago
img
2 years ago
js
2 years ago
partials
2 years ago
class-email.php
2 years ago
class-eqw-advance.php
2 years ago
class-eqw-enquiry-cart.php
2 years ago
class-eqw-enquiry-shortcode.php
2 years ago
class-eqw-product.php
2 years ago
class-eqw-save-enquiry.php
2 years ago
class-pisol-enquiry-quotation-woocommerce-public.php
2 years ago
class-pisol-form.php
2 years ago
class-webhook.php
2 years ago
index.php
2 years ago
class-eqw-enquiry-shortcode.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | class class_eqw_enquiry_shortcode{ |
| 4 | |
| 5 | public $products; |
| 6 | |
| 7 | function __construct(){ |
| 8 | |
| 9 | add_shortcode('pisol_enquiry_cart',array($this, 'enquiry_cart_template')); |
| 10 | /** this shortcode [enquiry_cart] is to support old sites */ |
| 11 | add_shortcode('enquiry_cart',array($this, 'enquiry_cart_template')); |
| 12 | add_action('wp_ajax_get_cart_on_load', array($this,'cartOnFirstLoad')); |
| 13 | add_action('wp_ajax_nopriv_get_cart_on_load', array($this,'cartOnFirstLoad')); |
| 14 | } |
| 15 | |
| 16 | function enquiry_cart_template(){ |
| 17 | ob_start(); |
| 18 | $this->products = class_eqw_enquiry_cart::getProductsInEnquirySession(); |
| 19 | include('partials/pisol-eqw-shortcode.php'); |
| 20 | $ret = ob_get_contents(); |
| 21 | ob_end_clean(); |
| 22 | return $ret; |
| 23 | } |
| 24 | |
| 25 | function cartOnFirstLoad(){ |
| 26 | $this->products = class_eqw_enquiry_cart::getProductsInEnquirySession(); |
| 27 | ob_start(); |
| 28 | pisol_table_row($this->products); |
| 29 | $cart = ob_get_contents(); // read ob2 ("b") |
| 30 | ob_end_clean(); |
| 31 | $data = array( |
| 32 | 'cart'=> $cart, |
| 33 | 'pisol_products'=> class_eqw_enquiry_cart::filter_message($this->products) |
| 34 | ); |
| 35 | echo json_encode($data, JSON_UNESCAPED_SLASHES); |
| 36 | die; |
| 37 | } |
| 38 | |
| 39 | static function get_price($product) { |
| 40 | if( $product->is_on_sale() ) { |
| 41 | return $product->get_sale_price(); |
| 42 | } |
| 43 | return $product->get_regular_price(); |
| 44 | } |
| 45 | |
| 46 | static function get_price_simple_variation($product, $variation_id){ |
| 47 | if ($product->is_type( 'simple' )) { |
| 48 | return self::get_price($product); |
| 49 | }elseif($product->is_type('variable')){ |
| 50 | $variation_product = new WC_Product_Variation( $variation_id ); |
| 51 | return self::get_price($variation_product); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | static function get_variations($product, $variations_detail, $echo = false){ |
| 56 | // test if product is variable |
| 57 | if($variations_detail == null || $variations_detail == "" || $variations_detail == false){ |
| 58 | return ; |
| 59 | } |
| 60 | |
| 61 | $variations = ""; |
| 62 | $variations_label = array(); |
| 63 | if( $product->is_type( 'variable' ) ){ |
| 64 | // Loop through available product variation data |
| 65 | foreach ( $variations_detail as $attribute => $term_slug ) { |
| 66 | // Loop through the product attributes for this variation |
| 67 | $taxonomy = str_replace( 'attribute_', '', $attribute ); |
| 68 | $attr_label_name = wc_attribute_label( $taxonomy ); |
| 69 | |
| 70 | $term_obj = get_term_by( 'slug', $term_slug, $taxonomy ); |
| 71 | $term_name = is_object($term_obj) ? $term_obj->name : $term_slug; |
| 72 | $variations_label[$attr_label_name] = $term_name; |
| 73 | |
| 74 | } |
| 75 | } |
| 76 | if($echo){ |
| 77 | self::variation_html($variations_label); |
| 78 | }else{ |
| 79 | return $variations_label; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | static function variation_html($variations_label){ |
| 84 | if(is_array($variations_label)){ |
| 85 | echo '<br>'; |
| 86 | foreach ($variations_label as $key => $value){ |
| 87 | echo '<strong class="pi-attribute-label">'.$key.'</strong> : <span>'.$value.'</span><br>'; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | } |
| 93 | |
| 94 | new class_eqw_enquiry_shortcode(); |