Forum

Thread tagged as: Members, Shop

Customers paying a deposit - via perch member tag

Hi There,

We are nearly there with our shop launch, we are working on the option for customers to pay a deposit and once paid the other product appears with the remaining balance.

I am just struggling on how we could get this working.

I realise we need the code

if (perch_member_has_tag(‘paidcontent’)) {
  // do some stuff here
}

But how do we get it to match the deposit product and the remaining balance product

Any help on this would be great

Thanks

Fishtank Creative

Fishtank Creative 2 points

  • 5 years ago

I managed to get this sorted. Took me all day but we got there.

Solution

Firstly on the product.html we removed the sku from the slug field so it displayed

<perch:shop id="slug" type="slug" editable="true" indelible="true" label="Slug" for="title" order="10" divider-before="Meta data" />

So from here we could give the deposit product and the remainder product the same title but each product has a different sku. The deposit sku must contain -DEP and the remainder product sku must contain -BAL

When then give the deposit product a tag which must be the same as the deposit sku.

So from here I was able to do the following code to get it working

<?php
    if (perch_get('s')) {

        $sku = perch_shop_products([
            'template'      =>'products/product_sku.html',
            'filter'=>array(
                array(
                    'filter'=>'slug',
                    'match'=>'eq',
                    'value'=>perch_get('s')
                ),
                array(
                    'filter'=>'sku',
                    'match'=>'contains',
                    'value' => 'DEP'
                ),
            )
        ], true);


        // Strips out all whitespace
        $tag = preg_replace('/\s+/', '', $sku);

        if (perch_member_has_tag($tag)) {

            perch_shop_product(perch_get('s'), [
                'template' => 'products/product_v2.html',
                'filter'=>array(
                    array(
                        'filter'=>'slug',
                        'match'=>'eq',
                        'value'=>perch_get('s')
                    ),
                    array(
                        'filter'=>'sku',
                        'match'=>'contains',
                        'value' => 'BAL'
                    ),
                )
            ]);

        } else {

            perch_shop_product(perch_get('s'), [
                'template' => 'products/product_v2.html',
                'filter'=>array(
                    array(
                        'filter'=>'slug',
                        'match'=>'eq',
                        'value'=>perch_get('s')
                    ),
                    array(
                        'filter'=>'sku',
                        'match'=>'contains',
                        'value' => 'DEP'
                    ),
                )
            ]);

        }

    }
?>

This seems to work for us, but there probably is an easier way to do this. I am always open to ways to make my code cleaner so feel free.

Thanks