Templates
2 weeks ago
TranslationEditor
2 weeks ago
Calendar.php
1 year ago
Emails.php
2 weeks ago
Factory.php
2 weeks ago
MulticurrencyHooks.php
2 weeks ago
Prices.php
2 weeks ago
SharedHooks.php
2 weeks ago
Slots.php
2 weeks ago
class-wcml-accommodation-bookings.php
2 weeks ago
class-wcml-bookings.php
2 weeks ago
Slots.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\WcBookings; |
| 4 | |
| 5 | use function WPML\FP\spreadArgs; |
| 6 | use WPML\FP\Obj; |
| 7 | use WPML\LIB\WP\Hooks; |
| 8 | |
| 9 | class Slots implements \IWPML_Action { |
| 10 | |
| 11 | public function add_hooks() { |
| 12 | Hooks::onAction( 'woocommerce_after_product_object_save' ) |
| 13 | ->then( spreadArgs( [ $this, 'deleteTranslationsSlotsTransients' ] ) ); |
| 14 | } |
| 15 | |
| 16 | public function deleteTranslationsSlotsTransients( $product ) { |
| 17 | if ( ! $product instanceof \WC_Product_Booking ) { |
| 18 | return; |
| 19 | } |
| 20 | $productId = (int) $product->get_id(); |
| 21 | $type = apply_filters( 'wpml_element_type', get_post_type( $productId ) ); |
| 22 | $trid = apply_filters( 'wpml_element_trid', false, $productId, $type ); |
| 23 | $translations = apply_filters( 'wpml_get_element_translations', [], $trid, $type ); |
| 24 | |
| 25 | wpml_collect( $translations ) |
| 26 | ->filter( function( $translation ) use ( $productId ) { |
| 27 | return (int) Obj::prop( 'element_id', $translation ) !== $productId; |
| 28 | } ) |
| 29 | ->map( function( $translation ) { |
| 30 | \WC_Bookings_Cache::delete_booking_slots_transient( $translation->element_id ); |
| 31 | } ); |
| 32 | } |
| 33 | |
| 34 | } |
| 35 |