← All changes
|
integrations/woocommerce/includes/ajax-functions.php
+44
-0
7.9.2
→
8.0.5
View file →
| @@ -1,0 +1,44 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Ajax Functions | |
| 4 | + * | |
| 5 | + * @package GamiPress\WooCommerce\Ajax_Functions | |
| 6 | + * @since 1.1.3 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +// Return product variations dropdown for requirements UI | |
| 13 | +function gamipress_wc_ajax_get_product_variations() { | |
| 14 | + | |
| 15 | + $product_id = $_POST['post_id']; | |
| 16 | + $site_id = $_POST['site_id']; | |
| 17 | + $selected = $_POST['selected']; | |
| 18 | + | |
| 19 | + if( gamipress_is_network_wide_active() && $site_id !== get_current_blog_id() ) { | |
| 20 | + switch_to_blog( $site_id ); | |
| 21 | + $product = wc_get_product( $product_id ); | |
| 22 | + restore_current_blog(); | |
| 23 | + } else { | |
| 24 | + $product = wc_get_product( $product_id ); | |
| 25 | + } | |
| 26 | + | |
| 27 | + // Bail if product doesn't exists | |
| 28 | + if( ! $product ) { | |
| 29 | + die(); | |
| 30 | + } | |
| 31 | + | |
| 32 | + $output = gamipress_wc_get_product_variations_dropdown( $product_id, $selected, $site_id ); | |
| 33 | + | |
| 34 | + // Bail if product has no variations | |
| 35 | + if( empty( $output ) ) { | |
| 36 | + echo '<span style="color: #a00;">This product has no variations</span>'; | |
| 37 | + die(); | |
| 38 | + } | |
| 39 | + | |
| 40 | + echo $output; | |
| 41 | + die(); | |
| 42 | + | |
| 43 | +} | |
| 44 | +add_action( 'wp_ajax_gamipress_wc_get_product_variations', 'gamipress_wc_ajax_get_product_variations' ); | |