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-product.php
187 lines
| 1 | <?php |
| 2 | |
| 3 | class class_eqw_product{ |
| 4 | |
| 5 | public $single_product_enquiry_position; |
| 6 | public $loop_product_enquiry_position; |
| 7 | public $add_to_enquiry_text_loop; |
| 8 | public $add_to_enquiry_text_single; |
| 9 | public $trouble_shoot_position; |
| 10 | |
| 11 | |
| 12 | function __construct(){ |
| 13 | |
| 14 | /** |
| 15 | * https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/ |
| 16 | */ |
| 17 | $this->single_product_enquiry_position = 52; |
| 18 | |
| 19 | $this->loop_product_enquiry_position = 'woocommerce_after_shop_loop_item'; |
| 20 | |
| 21 | $this->add_to_enquiry_text_loop = get_option('pi_eqw_enquiry_loop_button_text','Add to Enquiry'); |
| 22 | $this->add_to_enquiry_text_single = get_option('pi_eqw_enquiry_single_button_text','Add to Enquiry'); |
| 23 | |
| 24 | $this->trouble_shoot_position = get_option('pi_eqw_trouble_shoot_position',0); |
| 25 | |
| 26 | if($this->trouble_shoot_position){ |
| 27 | add_action( 'woocommerce_single_product_summary', array($this,'add_enquiry_button'), $this->single_product_enquiry_position); |
| 28 | }else{ |
| 29 | add_action( 'woocommerce_after_template_part', array($this,'add_enquiry_button_new'), 10,1); |
| 30 | } |
| 31 | |
| 32 | add_action($this->loop_product_enquiry_position, array($this,'add_loop_enquiry_button'), 50 ); |
| 33 | |
| 34 | } |
| 35 | |
| 36 | static function styleProductPage(){ |
| 37 | $button_width_single = get_option('pisol_eqw_button_size', ''); |
| 38 | $button_font_single = get_option('pisol_eqw_button_font_size', '16'); |
| 39 | |
| 40 | if(!empty($button_width_single)){ |
| 41 | $width = " width:{$button_width_single}px; "; |
| 42 | }else{ |
| 43 | $width = ''; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | if(!empty($button_font_single)){ |
| 48 | $font = " font-size:{$button_font_single}px; "; |
| 49 | }else{ |
| 50 | $font = ''; |
| 51 | } |
| 52 | |
| 53 | $style = 'style="'.esc_attr($width.$font).'"'; |
| 54 | return $style; |
| 55 | } |
| 56 | |
| 57 | static function styleLoopPage(){ |
| 58 | $button_width_loop = get_option('pisol_eqw_loop_button_size', ''); |
| 59 | $button_font_loop = get_option('pisol_eqw_loop_button_font_size', '16'); |
| 60 | |
| 61 | if(!empty($button_width_loop)){ |
| 62 | $width = " width:{$button_width_loop}px; "; |
| 63 | }else{ |
| 64 | $width = ''; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | if(!empty($button_font_loop)){ |
| 69 | $font = " font-size:{$button_font_loop}px; "; |
| 70 | }else{ |
| 71 | $font = ''; |
| 72 | } |
| 73 | |
| 74 | $style = 'style="'.esc_attr($width.$font).'"'; |
| 75 | return $style; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * remove this after few releases as this is old way of adding |
| 80 | * button |
| 81 | */ |
| 82 | function add_enquiry_button(){ |
| 83 | global $product; |
| 84 | |
| 85 | if(!$this->showButtonOnSinglePage($product)) return; |
| 86 | |
| 87 | $style = self::styleProductPage(); |
| 88 | |
| 89 | if($product->is_type('variable') ){ |
| 90 | echo '<button class="button pi-custom-button add-to-enquiry add-to-enquiry-single" href="javascript:void(0)" data-action="pi_add_to_enquiry" data-id="'.esc_attr($product->get_id()).'" '.$style.'>' . esc_html($this->add_to_enquiry_text_single). '</button>'; |
| 91 | }else{ |
| 92 | echo '<button class="button pi-custom-button add-to-enquiry add-to-enquiry-single" href="javascript:void(0)" data-action="pi_add_to_enquiry" data-id="'.esc_attr($product->get_id()).'" '.$style.'>' . esc_html($this->add_to_enquiry_text_single). '</button>'; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | function add_enquiry_button_new($tmp_name){ |
| 97 | |
| 98 | if(in_array($tmp_name, array('single-product/add-to-cart/simple.php'))){ |
| 99 | global $product; |
| 100 | if(is_object($product)){ |
| 101 | if(!$this->showButtonOnSinglePage($product)) return; |
| 102 | |
| 103 | $style = self::styleProductPage(); |
| 104 | |
| 105 | if($product->is_type('variable') ){ |
| 106 | echo '<button class="button pi-custom-button add-to-enquiry add-to-enquiry-single" href="javascript:void(0)" data-action="pi_add_to_enquiry" data-id="'.$product->get_id().'" '.$style.'>' . esc_html($this->add_to_enquiry_text_single). '</button>'; |
| 107 | }else{ |
| 108 | echo '<button class="button pi-custom-button add-to-enquiry add-to-enquiry-single" href="javascript:void(0)" data-action="pi_add_to_enquiry" data-id="'.$product->get_id().'" '.$style.'>' . esc_html($this->add_to_enquiry_text_single). '</button>'; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | function add_loop_enquiry_button() { |
| 115 | global $product; |
| 116 | |
| 117 | if(!$this->showButtonOnLoopPage($product)) return; |
| 118 | |
| 119 | $style = self::styleLoopPage(); |
| 120 | |
| 121 | if($product->is_type('variable') ){ |
| 122 | echo '<div style="margin-bottom:10px; text-align:center; width:100%;"> |
| 123 | <a class="button pi-custom-button add-to-enquiry-loop" href="'.$product->get_permalink().'" '.$style.'>'.esc_html($this->add_to_enquiry_text_loop).'</a> |
| 124 | </div>'; |
| 125 | }else{ |
| 126 | echo '<div style="margin-bottom:10px; text-align:center; width:100%;"> |
| 127 | <a class="button pi-custom-button add-to-enquiry add-to-enquiry-loop" href="javascript:void(0)" data-action="pi_add_to_enquiry" data-id="'.$product->get_id().'" '.$style.'>'.esc_html($this->add_to_enquiry_text_loop).'</a> |
| 128 | </div>'; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | function showButtonOnLoopPage($product){ |
| 133 | if( $product->is_type('grouped') || $product->is_type('variable') ) return false; |
| 134 | |
| 135 | |
| 136 | /** |
| 137 | * this show enquiry if product is out of stock and you want to show when product is out of stock |
| 138 | */ |
| 139 | /* |
| 140 | $pi_eqw_loop_show_on_out_of_stock = get_option('pi_eqw_loop_show_on_out_of_stock', 0); |
| 141 | if($pi_eqw_loop_show_on_out_of_stock == 1){ |
| 142 | if(!$product->is_in_stock()){ |
| 143 | return true; |
| 144 | } |
| 145 | } |
| 146 | */ |
| 147 | /** |
| 148 | * global loop is off, |
| 149 | * but still you can enable it for single product from product overwrite |
| 150 | * enable it for out of stocks |
| 151 | */ |
| 152 | $pi_eqw_enquiry_loop = get_option('pi_eqw_enquiry_loop',0); |
| 153 | if($pi_eqw_enquiry_loop != 1) return false; |
| 154 | |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | function showButtonOnSinglePage($product){ |
| 159 | if( $product->is_type('grouped') || $product->is_type('variable')) return false; |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * this show enquiry if product is out of stock and you want to show when product is out of stock |
| 164 | */ |
| 165 | /* |
| 166 | $pi_eqw_single_show_on_out_of_stock = get_option('pi_eqw_single_show_on_out_of_stock', 0); |
| 167 | if($pi_eqw_single_show_on_out_of_stock == 1){ |
| 168 | if(!$product->is_in_stock()){ |
| 169 | return true; |
| 170 | } |
| 171 | } |
| 172 | */ |
| 173 | /** |
| 174 | * global single is off, |
| 175 | * but still you can enable it for single product from product overwrite |
| 176 | * enable it for out of stocks |
| 177 | */ |
| 178 | $pi_eqw_enquiry_single = get_option('pi_eqw_enquiry_single',1); |
| 179 | if($pi_eqw_enquiry_single != 1) return false; |
| 180 | |
| 181 | return true; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | new class_eqw_product(); |
| 186 | |
| 187 |