Changeset 2627190
- Timestamp:
- 11/10/2021 09:26:52 AM (4 years ago)
- Location:
- yourplugins-wc-conditional-cart-notices/trunk
- Files:
-
- 8 edited
-
app/notice/notice-entity.php (modified) (1 diff)
-
app/query-builder/query-builder-helper.php (modified) (2 diffs)
-
app/query-builder/query-builder-model.php (modified) (1 diff)
-
composer.json (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
vendor/yps/framework-query-builder/css/query-builder.css (modified) (1 diff)
-
vendor/yps/framework-woocommerce/includes/woocommerce-product-helper.php (modified) (3 diffs)
-
yourplugins-wc-conditional-cart-notices.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
yourplugins-wc-conditional-cart-notices/trunk/app/notice/notice-entity.php
r2624373 r2627190 39 39 } 40 40 41 $rows = $query_builder_model->get_query_rows("SELECT * FROM {$query_builder_model->table} WHERE {$notice_rule_sql}"); 41 $notice_rule_sql = apply_filters('yps_wc_conditional_cart_notices_sql_rule', $notice_rule_sql); 42 $rows = $query_builder_model->get_query_rows("SELECT * FROM {$query_builder_model->table} WHERE {$notice_rule_sql}"); 42 43 43 44 $query_builder_helper->drop_tmp_table(); -
yourplugins-wc-conditional-cart-notices/trunk/app/query-builder/query-builder-helper.php
r2625033 r2627190 76 76 foreach($categories as $category){ 77 77 foreach($roles as $role){ 78 $query_builder_model->insert_row(a rray(78 $query_builder_model->insert_row(apply_filters('yps_wc_conditional_cart_notices_query_builder_row', array( 79 79 'categories' => $category->term_id, 80 80 'products' => $product_id, … … 99 99 100 100 'referrer_url' => (isset($_SERVER['HTTP_REFERER']))?$_SERVER['HTTP_REFERER']:"", 101 )) ;101 ))); 102 102 } 103 103 } -
yourplugins-wc-conditional-cart-notices/trunk/app/query-builder/query-builder-model.php
r2521920 r2627190 19 19 public function create_table(){ 20 20 21 $ sql = "CREATE TEMPORARY TABLE {$this->table}(22 `id` int(11) NOT NULL AUTO_INCREMENT,21 $columns = apply_filters('yps_wc_conditional_cart_notices_query_builder_table_columns', array( 22 "`id` int(11) NOT NULL AUTO_INCREMENT", 23 23 24 `categories` int(11) DEFAULT NULL, 25 `products` int(11) DEFAULT NULL, 26 `user_roles` varchar(255) DEFAULT NULL, 27 `user_types` varchar(50) DEFAULT NULL, 24 "`categories` int(11) DEFAULT NULL", 25 "`products` int(11) DEFAULT NULL", 28 26 29 `billing_country` varchar(5) DEFAULT NULL,30 `shipping_country` varchar(5) DEFAULT NULL,27 "`user_roles` varchar(255) DEFAULT NULL", 28 "`user_types` varchar(50) DEFAULT NULL", 31 29 32 `datetime` DATETIME DEFAULT NULL, 30 "`billing_country` varchar(5) DEFAULT NULL", 31 "`shipping_country` varchar(5) DEFAULT NULL", 33 32 34 `price` decimal(6,2) DEFAULT NULL, 35 `product_quantity` int(11) DEFAULT NULL, 33 "`datetime` DATETIME DEFAULT NULL", 36 34 37 `total_quantity` decimal(6,2) DEFAULT NULL, 38 `total_amount` decimal(6,2) DEFAULT NULL, 39 `total_net_amount` decimal(6,2) DEFAULT NULL, 40 `total_taxes` decimal(6,2) DEFAULT NULL, 41 `shipping_total` decimal(6,2) DEFAULT NULL, 42 `total_coupon_discount_amount` decimal(6,2) DEFAULT NULL, 35 "`price` decimal(6,2) DEFAULT NULL", 36 "`product_quantity` int(11) DEFAULT NULL", 37 38 "`total_quantity` decimal(6,2) DEFAULT NULL", 39 "`total_amount` decimal(6,2) DEFAULT NULL", 40 "`total_net_amount` decimal(6,2) DEFAULT NULL", 41 "`total_taxes` decimal(6,2) DEFAULT NULL", 42 "`shipping_total` decimal(6,2) DEFAULT NULL", 43 "`total_coupon_discount_amount` decimal(6,2) DEFAULT NULL", 43 44 44 `referrer_url` MEDIUMTEXT DEFAULT NULL, 45 PRIMARY KEY (`id`) 46 ){$this->get_charset_collate()};"; 45 "`referrer_url` MEDIUMTEXT DEFAULT NULL" 46 )); 47 48 $sql = "CREATE TEMPORARY TABLE {$this->table} (" . implode(",", $columns) . ", PRIMARY KEY (`id`) ) {$this->get_charset_collate()};"; 47 49 48 50 $this->query($sql); -
yourplugins-wc-conditional-cart-notices/trunk/composer.json
r2521920 r2627190 2 2 3 3 "require": { 4 "yps/framework-composer": " 2.0.3",4 "yps/framework-composer": "dev-trunk", 5 5 6 6 "yps/framework-core": "2.0.6", -
yourplugins-wc-conditional-cart-notices/trunk/readme.txt
r2625033 r2627190 4 4 Requires at least: 4.3.1 5 5 Tested up to: 5.8.1 6 Stable tag: 1.0. 86 Stable tag: 1.0.9 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 52 52 == Changelog == 53 53 54 * 1.0.9 [05/11/2021]: 55 - Bugfixes and adding filters 56 54 57 * 1.0.8 [05/11/2021]: 55 58 - Bugfixes 56 59 57 60 * 1.0.7 [04/11/2021]: 58 61 - Bugfixes -
yourplugins-wc-conditional-cart-notices/trunk/vendor/yps/framework-query-builder/css/query-builder.css
r2521920 r2627190 27 27 user-select: none !important; 28 28 } 29 30 .yps-bootstrap .search-choice.search-choice-disabled { 31 background-color: white !important; 32 border: 0px solid white !important; 33 margin: 9px !important; 34 padding: 0px !important; 35 opacity: 0.7 !important; 36 } 37 38 .yps-bootstrap .search-choice.search-choice-disabled span { 39 background-color: white !important; 40 } -
yourplugins-wc-conditional-cart-notices/trunk/vendor/yps/framework-woocommerce/includes/woocommerce-product-helper.php
r2521920 r2627190 2 2 3 3 namespace YPS\Framework\Woocommerce\v2_0_6; 4 5 use YPS\Framework\Woocommerce\v2_0_6\Woocommerce_Helper;6 4 7 5 class Woocommerce_Product_Helper { … … 23 21 24 22 $products = array(); 25 $ret = Woocommerce_Helper::get_products($query_args);23 $ret = self::get_products($query_args); 26 24 27 25 foreach($ret['products'] as $product){ … … 46 44 } 47 45 48 49 50 46 /** 47 * Get a product attribute by its name 48 * 49 * @param string $attribute_name Name of the attribute 50 * @param type $product WooCommerce Product 51 * @return WC_Product_Attribute https://docs.woocommerce.com/wc-apidocs/class-WC_Product_Attribute.html 52 */ 53 public static function get_product_attribute($attribute_name, $product){ 54 55 // For Product Variation type 56 if( $product->get_parent_id() > 0 ){ 57 $parent = \wc_get_product($product->get_parent_id()); 58 $attributes = $parent->get_attributes(); 59 // For other Product types 60 }else{ 61 $attributes = $product->get_attributes(); 62 } 63 64 if(isset($attributes["pa_{$attribute_name}"])){ 65 return $attributes["pa_{$attribute_name}"]; 66 } 67 68 return null; 69 } 70 71 /** 72 * Get an attribute from product without worrying about if it's a variation or simple product 73 * 74 * @param string $attribute_name Name of the attribute 75 * @param type $product WooCommerce Product 76 * @return string 77 */ 78 public static function get_product_attribute_value($attribute_name, $product){ 79 $attribute = null; 80 81 // For Product Variation type 82 if( $product->get_parent_id() > 0 ){ 83 $parent = \wc_get_product($product->get_parent_id()); 84 $attribute = $parent->get_attribute($attribute_name); 85 86 // For other Product types 87 }else{ 88 $attribute = $product->get_attribute($attribute_name); 89 } 90 91 return $attribute; 92 } 93 94 /** 95 * Giving a WooCommerce "package" calculates the total weight 96 * 97 * @param "package" $package 98 * @return int Total Package Weigth 99 */ 100 public static function calculate_package_total_weigth($package){ 101 $weight = 0; 102 103 foreach($package['contents'] as $key => $row){ 104 $product_weight = $row['data']->get_weight(); 105 106 if(!empty($product_weight)){ 107 $weight += $row['quantity']*$product_weight; 108 } 109 } 110 111 return $weight; 112 } 113 114 public static function calculate_package_total($package){ 115 $price = 0; 116 117 foreach($package['contents'] as $key => $row){ 118 $price += $row['line_total']+$row['line_tax']; 119 } 120 121 return $price; 122 } 123 124 public static function get_tax_classes(){ 125 $slugs = \WC_Tax::get_tax_class_slugs(); 126 $labels = \WC_Tax::get_tax_classes(); 127 128 $classes = array(); 129 130 $classes[] = array( 131 'class_name' => 'Standard', 132 'rates' => \WC_Tax::get_rates() 133 ); 134 135 foreach($slugs as $index => $slug){ 136 $classes[$slug] = array( 137 'class_name' => $labels[$index], 138 'rates' => \WC_Tax::get_rates($slug) 139 140 ); 141 } 142 143 144 145 return $classes; 146 } 147 148 public static function get_shipping_tax_rates(){ 149 $tax_classes = self::get_tax_classes(); 150 $shipping_rates = array(); 151 152 foreach($tax_classes as $tax_class){ 153 foreach($tax_class['rates'] as $rate){ 154 if($rate['shipping'] == 'yes'){ 155 $shipping_rates[] = $rate; 156 } 157 } 158 } 159 160 return $shipping_rates; 161 } 162 163 /** 164 * Return a list of all the Woocommerce products. 165 * 166 * @param int $productsPerPage number of product to return (-1 for no limits) 167 * @param int $start offset to start 168 * @param string $orderBy type of order 169 * @param string $orderDir the directory order 170 * @param string $search 171 * @return array 172 */ 173 public static function get_products($query_args = array(), $only_id = false){ 174 175 $products = array(); 176 177 $args = array( 178 'post_type' => 'product', 179 ); 180 181 $args = array_merge($args, $query_args); 182 183 $loop = new \WP_Query($args); 184 $totalProducts = $loop->found_posts; 185 $count = $loop->post_count; 186 187 while ( $loop->have_posts() ) : $loop->the_post(); 188 global $product; 189 190 if($only_id == true){ 191 $products[] = $product->get_id(); 192 }else{ 193 $products[] = $product; 194 } 195 196 endwhile; 197 wp_reset_query(); 198 199 200 return array( 201 'products' => $products, 202 'totalProducts' => $totalProducts, 203 'count' => $count, 204 ); 205 206 } 207 208 public static function get_product_tags($product_id){ 209 $terms = get_the_terms($product_id, 'product_tag'); 210 $tags = array(); 211 212 if (!empty($terms) && !is_wp_error($terms) ){ 213 foreach ($terms as $term) { 214 $tags[] = $term; 215 } 216 } 217 218 return $tags; 219 } 220 221 public static function get_all_product_tags($query_args = array()){ 222 223 $args = array( 224 'posts_per_page' => -1, 225 ) + $query_args; 226 227 $products = self::get_products($args, true); 228 $all_tags = array(); 229 230 //print_r($products['products']); 231 232 foreach($products['products'] as $product_id){ 233 $tags = self::get_product_tags($product_id); 234 235 foreach($tags as $tag){ 236 $all_tags[$tag->term_id] = $tag; 237 } 238 } 239 240 return $all_tags; 241 } 242 243 244 /** 245 * Products category. 246 * 247 * Get the categories of all the products searching by slug. 248 * 249 * @param string $productCategoryName the category ofa product 250 * @return array 251 */ 252 public static function get_products_by_category_slug($productCategorySlug = null){ 253 /* Using Raw MySQL Query instead of \WP_Query which throw a "Allowed memory" error */ 254 $database_helper = new Database_Helper(); 255 256 257 $rows = $database_helper->get_query_rows("SELECT object_id FROM [prefix]terms 258 LEFT JOIN [prefix]term_taxonomy ON [prefix]term_taxonomy.term_id = [prefix]terms.term_id 259 LEFT JOIN [prefix]term_relationships ON [prefix]term_relationships.term_taxonomy_id = [prefix]term_taxonomy.term_taxonomy_id 260 WHERE slug = :slug 261 AND taxonomy = 'product_cat';", array( 262 'slug' => $productCategorySlug, 263 )); 264 265 $products = array(); 266 foreach($rows as $row){ 267 $products[] = $row->object_id; 268 } 269 270 return $products; 271 } 272 273 /** 274 * Products category. 275 * 276 * Get the categories of all the products searching by ID. 277 * 278 * @param int $categoryId the id of a specific category 279 * @return array 280 */ 281 public static function get_products_by_category_id($categoryId = null){ 282 $term = get_term($categoryId, 'product_cat'); 283 284 if(empty($term)){ 285 return array(); 286 } 287 288 if($categoryId == null){ 289 $slug = null; 290 }else{ 291 $slug = $term->slug; 292 } 293 294 return self::get_products_by_category_slug($slug); 295 } 296 297 /** 298 * 299 * @param string $field: 'slug' => Search for slug, 'id' => Search for ID 300 */ 301 public static function get_products_by_tag($search, $field = 'slug'){ 302 $all_ids = get_posts( array( 303 'post_type' => 'product', 304 'numberposts' => -1, 305 'post_status' => 'publish', 306 'fields' => 'ids', 307 'tax_query' => array( 308 array( 309 'taxonomy' => 'product_tag', 310 'field' => $field, 311 'terms' => $search, 312 'operator' => 'IN', 313 ) 314 ), 315 )); 316 317 return $all_ids; 318 } 319 320 public static function get_products_by_merge($product_ids = array(), $category_ids = array(), $tag_ids = array()){ 321 $ret_ids = array(); 322 323 $ret_ids = array_merge($ret_ids, $product_ids); 324 325 foreach($category_ids as $category_id){ 326 $category_products = self::get_products_by_category_id($category_id); 327 $ret_ids = array_merge($ret_ids, $category_products); 328 } 329 330 foreach($tag_ids as $tag_id){ 331 $tag_products = self::get_products_by_tag($tag_id, 'id'); 332 $ret_ids = array_merge($ret_ids, $tag_products); 333 } 334 335 return $ret_ids; 336 } 337 338 public static function price_to_db($price){ 339 $decimal_separator = \wc_get_price_decimal_separator(); 340 341 return floatval(str_replace($decimal_separator, ".", $price)); 342 } 343 344 public static function price_from_db($price){ 345 $decimal_separator = \wc_get_price_decimal_separator(); 346 347 return str_replace(".", $decimal_separator, $price); 348 } 349 350 public static function delete_product($id, $force = FALSE){ 351 $product = \wc_get_product($id); 352 353 if(empty($product)){ 354 return false; 355 } 356 357 // If we're forcing, then delete permanently. 358 if($force){ 359 if($product->is_type('variable')){ 360 361 foreach ($product->get_children() as $child_id){ 362 $child = \wc_get_product($child_id); 363 $child->delete(true); 364 } 365 }else if ($product->is_type('grouped')){ 366 foreach ($product->get_children() as $child_id) 367 { 368 $child = \wc_get_product($child_id); 369 $child->set_parent_id(0); 370 $child->save(); 371 } 372 } 373 374 $product->delete(true); 375 $result = $product->get_id() > 0 ? false : true; 376 }else{ 377 $product->delete(); 378 $result = 'trash' === $product->get_status(); 379 } 380 381 if(!$result){ 382 return false; 383 } 384 385 // Delete parent product transients. 386 if($parent_id = wp_get_post_parent_id($id)){ 387 \wc_delete_product_transients($parent_id); 388 } 389 390 return true; 391 } 392 393 public static function get_product_image_src($post){ 394 $data = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID)); 395 396 if(empty($data[0])){ 397 return \wc_placeholder_img_src(); 398 } 399 400 return $data[0]; 401 } 402 403 /** 404 * Redirect user to WooCommerce My Account 405 */ 406 public static function redirect_to_my_account(){ 407 wp_redirect(get_permalink(get_option('woocommerce_myaccount_page_id'))); 408 } 409 410 public static function is_product_attribute_in_cart($attribute_name, $attribute_value){ 411 global $woocommerce; 412 413 $items = $woocommerce->cart->get_cart(); 414 415 foreach($items as $item => $values) { 416 $product = \wc_get_product($values['data']->get_id()); 417 418 if(empty($product->get_parent_id())){ 419 $value = $product->get_attribute($attribute_name); 420 }else{ 421 $parent = \wc_get_product($product->get_parent_id()); 422 $value = $parent->get_attribute($attribute_name); 423 } 424 425 if($value == $attribute_value){ 426 return true; 427 } 428 } 429 430 return false; 431 } 432 433 public static function is_product_attribute_in_order($order, $attribute_name, $attribute_value){ 434 435 foreach($order->get_items() as $item_key => $item){ 436 $product = $item->get_product(); 437 438 if(empty($product->get_parent_id())){ 439 $value = $product->get_attribute($attribute_name); 440 }else{ 441 $parent = \wc_get_product($product->get_parent_id()); 442 $value = $parent->get_attribute($attribute_name); 443 } 444 445 if($value == $attribute_value){ 446 return true; 447 } 448 } 449 450 return false; 451 } 51 452 52 453 } 454 -
yourplugins-wc-conditional-cart-notices/trunk/yourplugins-wc-conditional-cart-notices.php
r2625033 r2627190 5 5 Plugin Code: yps-wc-conditional-cart-notices 6 6 Description: YourPlugins Conditional Cart Notices for WooCommerce 7 Version: 1.0. 87 Version: 1.0.9 8 8 Author: yourplugins.com 9 9 Author URI: https://yourplugins.com … … 22 22 $context->set_plugin_file(__FILE__); 23 23 $context->set_plugin_namespace("\\YPS\\WC_Conditional_Cart_Notices"); 24 $context->set_plugin_version("1.0. 8");24 $context->set_plugin_version("1.0.9"); 25 25 $context->set_init_priority(1000); 26 26
Note: See TracChangeset
for help on using the changeset viewer.