• Resolved Shah Paran Srijan

    (@mspsrijan)


    I believe this is more of a feature request than a support request. I have a 3 stepped funnel- opt-in, checkout and thank you. The opt-in provides a free PDF, the checkout has a paid product. I want the free downloadable file from the opt-in to be shown on the thank you page.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Shravan Bhaskaravajjula

    (@bhshravankumar)

    Hello @mspsrijan,

    Usually, the opt-in/lead magnet pages offers a free product to get the user details and shares the product through email.

    BTW, the download files on the thank you page is handled by the WooCommerce, CartFlows do not control this.

    I am not sure if this functionality is possible because it needs a lot of customization, it need to stop the product to be shared by the email and add it to downloads on the thank you page.

    I will forward the suggestion to our internal team for further review.

    Best,

    Thread Starter Shah Paran Srijan

    (@mspsrijan)

    I don’t think you need to stop sending the product via email in order add the downloads on the thank you page. I am adding my work so far if it comes in any help.

    I have created a shorcode [check_product_purchase product_ids=”ID”]. This takes the order number from the thank you page’s URL parameter, fetch the billing email, check if the registered user/guest user has purchased the product before and show a download link on the shortcode block. However, my code can’t provide access to the guest user, so the download is not working.

    function has_bought_items( $user_var = 0,  $product_ids = 0 ) {
        global $wpdb;
        
        // Based on user ID (registered users)
        if ( is_numeric( $user_var) ) { 
            $meta_key     = '_customer_user';
            $meta_value   = $user_var == 0 ? (int) get_current_user_id() : (int) $user_var;
        } 
        // Based on billing email (Guest users)
        else { 
            $meta_key     = '_billing_email';
            $meta_value   = sanitize_email( $user_var );
        }
        
        $paid_statuses    = array_map( 'esc_sql', wc_get_is_paid_statuses() );
        $product_ids      = is_array( $product_ids ) ? implode(',', $product_ids) : $product_ids;
    
        $line_meta_value  = $product_ids !=  ( 0 || '' ) ? 'AND woim.meta_value IN ('.$product_ids.')' : 'AND woim.meta_value != 0';
    
        // Count the number of products
        $count = $wpdb->get_var( "
            SELECT COUNT(p.ID) FROM {$wpdb->prefix}posts AS p
            INNER JOIN {$wpdb->prefix}postmeta AS pm ON p.ID = pm.post_id
            INNER JOIN {$wpdb->prefix}woocommerce_order_items AS woi ON p.ID = woi.order_id
            INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS woim ON woi.order_item_id = woim.order_item_id
            WHERE p.post_status IN ( 'wc-" . implode( "','wc-", $paid_statuses ) . "' )
            AND pm.meta_key = '$meta_key'
            AND pm.meta_value = '$meta_value'
            AND woim.meta_key IN ( '_product_id', '_variation_id' ) $line_meta_value 
        " );
    
        // Return true if count is higher than 0 (or false)
        return $count > 0 ? true : false;
    }
    
    function check_product_purchase( $atts ) {
        $product_ids = isset( $atts['product_ids'] ) ? explode( ',', $atts['product_ids'] ) : array();
        $order_key = isset( $_GET['wcf-key'] ) ? sanitize_text_field( $_GET['wcf-key'] ) : '';
        $order_id = isset( $_GET['wcf-order'] ) ? absint( $_GET['wcf-order'] ) : 0;
    
        // If the order ID is not provided in the URL parameter, retrieve it using the order key
        if ( empty( $order_id ) && ! empty( $order_key ) ) {
            $order = wc_get_order_id_by_order_key( $order_key );
            if ( ! empty( $order ) ) {
                $order_id = $order;
            }
        }
    
        // If the order ID is not valid or not provided, return error message
        if ( empty( $order_id ) || ! $order = wc_get_order( $order_id ) ) {
            echo '<p>Error: Invalid or missing order ID.</p>';
            return;
        }
    
        $user_email = $order->get_billing_email();
    
        if ( has_bought_items( $user_email, $product_ids ) ) {
            // Get the downloadable files for the product(s)
            $downloads = array();
            foreach ( $product_ids as $product_id ) {
                $product = wc_get_product( $product_id );
                $product_downloads = $product->get_downloads();
                if ( ! empty( $product_downloads ) ) {
                    $downloads = array_merge( $downloads, $product_downloads );
                }
            }
    
            if ( ! empty( $downloads ) ) {
                echo '<p>You can download the following file(s):</p>';
                echo '<ul>';
                foreach ( $downloads as $download ) {
                    echo '<li><a href="' . esc_url( $download['file'] ) . '">' . esc_html( $download['name'] ) . '</a></li>';
                }
                echo '</ul>';
            } else {
                echo '<p>No downloadable files were found for the purchased product(s).</p>';
            }
        } else {
            echo '<p>This user has not yet purchased any of these products.</p>';
        }
    }
    
    add_shortcode( 'check_product_purchase', 'check_product_purchase' );
    
    Plugin Support Aamir

    (@aamiribsf)

    Hello @mspsrijan,

    Thank you for taking the time to share your feedback with us.

    We greatly appreciate your input and we will certainly pass along your comments to our development team for further consideration.

    They will evaluate the feasibility of adding the option you suggested and determine if it aligns with our product roadmap.

    Once again, thank you for your valuable suggestion. If you have any further feedback or concerns, please don’t hesitate to reach out to us.

    Best regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Downloadable files on the thank you page for the Free opt-in product’ is closed to new replies.