PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / hooks / price.php

price.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/hooks/price.php

54 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine\Hooks;
4
5 use StoreEngine\Classes\AbstractProduct;
6 use StoreEngine\Classes\Integration;
7 use StoreEngine\Classes\Product\SimpleProduct;
8 use StoreEngine\Classes\ProductFactory;
9 use WP_Post;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 class Price {
16
17
18 public static function init() {
19 $self = new self();
20 add_action('deleted_post', [ $self, 'delete_prices_and_integrations' ], 10, 2);
21 }
22
23 public function delete_prices_and_integrations( int $post_id, WP_Post $post ) {
24 if ( 'storeengine_product' !== $post->post_type ) {
25 return;
26 }
27
28 $product = ProductFactory::getProduct( $post_id );
29 $prices = $product->get_prices();
30 $price_ids = array_map(fn( $price) => $price->get_id(), $prices);
31 if ( empty( $price_ids ) ) {
32 return;
33 }
34 $placeholders = implode(',', array_fill(0, count($prices), '%d'));
35
36 global $wpdb;
37 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
38 $wpdb->delete($wpdb->prefix . 'storeengine_product_price', [ 'product_id' => $post_id ], [ '%d' ]);
39
40 $wpdb->query(
41 $wpdb->prepare(
42 "DELETE FROM {$wpdb->prefix}storeengine_integrations WHERE price_id in ($placeholders)",
43 ...$price_ids
44 )
45 );
46 // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
47
48 // clear cache.
49 wp_cache_flush_group(AbstractProduct::CACHE_GROUP);
50 wp_cache_flush_group(Integration::CACHE_GROUP);
51 }
52
53 }
54