• Resolved Bruno Rodrigues

    (@brunojti)


    We’re coding our store in a way that when I add the last item to a cart, parts of the single template are reloaded via ajax and we want to show the alert_container in this reloaded part.

    The thing is: shortcodes won’t work with ajax requests… So I needed to do this in my theme.

    if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
        $output    = ob_get_clean();
        $shortcode = new WOO_Product_Stock_Alert_Shortcode();
        $output .= $shortcode->display_stock_alert_form( [ 'product_id' => $product->id ] );
        echo $output;
    }

    For the previous code work, i needed to change get_alert_form function (in class-woo-product-stock-alert-frontend.php)

    function get_alert_form($attr) {
    		global $WOO_Product_Stock_Alert, $product;
    
    		if(is_null($product)){
    			$product = wc_get_product( $attr['product_id'] );
    		}
    		if ( empty( $product ) ) return;
    [...]
    

    And pass the $attr param forward in class-woo-product-stock-shotcode-display-stock-alert-form.php:22

    $WOO_Product_Stock_Alert->frontend->get_alert_form($attr);

    Hope you can make this change in the production code.
    Best regards

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Won’t show alert_container when adding product to cart via AJAX.’ is closed to new replies.