'invalid_nonce' ], 403 ); } $post_id = absint( $_POST['post_id'] ?? 0 ); $widget_id = isset( $_POST['widget_id'] ) ? sanitize_key( wp_unslash( $_POST['widget_id'] ) ) : ''; $page = max( 2, absint( $_POST['page'] ?? 2 ) ); $widget = EPPRO_Elementor_Helper::get_widget( $post_id, $widget_id, 'eppro-woo-products' ); if ( ! $widget || ! method_exists( $widget, 'render_ajax_page' ) ) { wp_send_json_error( [ 'message' => __( 'These products could not be loaded. Please reload the page.', 'admore-widgets-suite' ) ], 400 ); } wp_send_json_success( $widget->render_ajax_page( $page ) ); } public static function quick_view(): void { if ( ! check_ajax_referer( self::NONCE_ACTION, 'nonce', false ) ) { wp_send_json_error( [ 'code' => 'invalid_nonce' ], 403 ); } if ( ! function_exists( 'wc_get_product' ) ) { wp_send_json_error( [], 400 ); } $product_id = absint( $_POST['product_id'] ?? 0 ); $product = $product_id ? wc_get_product( $product_id ) : null; // Only products a visitor could open in the shop. if ( ! $product || 'publish' !== get_post_status( $product_id ) || ! $product->is_visible() || post_password_required( $product_id ) ) { wp_send_json_error( [ 'message' => __( 'Product not found.', 'admore-widgets-suite' ) ], 404 ); } ob_start(); self::render_quick_view( $product ); wp_send_json_success( [ 'html' => (string) ob_get_clean() ] ); } // ========================================================================= // Markup helpers // ========================================================================= private static function render_quick_view( \WC_Product $product ): void { $short = $product->get_short_description(); ?>
get_type() ]; if ( $product->is_purchasable() && $product->is_in_stock() ) { $classes[] = 'add_to_cart_button'; if ( $product->supports( 'ajax_add_to_cart' ) ) { $classes[] = 'ajax_add_to_cart'; } } ?> is_type( 'simple' ) ) : ?>data-quantity="1" rel="nofollow" aria-label="add_to_cart_description() ); ?>"> add_to_cart_text() ); ?> get_average_rating(); echo ''; } }