Forum

Thread tagged as: Question, Shop

How to detect if user has no files

How can I run a conditional for a customer having no files.

At the moment the tag that outputs the files to the users account will not load if there are no products. So in the debug I can see it's not calling the file_list.html due to the lack of files being present on the account. However, I would like to display to keep my layout balanced. Just a message to say something like, 'You have no files yet' etc.

I did try

if (perch_shop_purchased_files()) {
    perch_shop_purchased_files([
        'template' => 'products/files_list.html',
    ]);
} else{
    echo("No files found");
}

Am I miles off on this thought process?

Mathew Doidge

Mathew Doidge 2 points

  • 4 years ago

For products

$total = perch_shop_cart_item_count(array(),true);
                if ($total > 0) { 

I could be doing this the most inefficient way possible, but I arrived at a solution that appears to work.

$files = count(array_filter(perch_shop_purchased_files([
    'skip-template' => true,
    'return-html' => false,
    'raw' => true,
])));

// print_r($files); 
if ($files > 0) {
    perch_shop_purchased_files([
        'template' => 'products/files_list.html',
    ]);
} else{
    echo("<p><strong>Your purchased files</strong></p>");
    echo("<p>You have no purchased files.</p>");
}