I could probably occomplish what I need with maybe some repeated fields at point of registration, with each section of repeated fields being a child i.e. First name, surname, dob etc, and the subscription price could be (cost * number of repeats).
Does this sound as though it would be do able?
Yes that would work. You however will need a CB Code Field as well since you'll need to count the repeat rows. The below should work fine for this.
Code:
return count( json_decode( '[FIELD_NAME]' ) );
This should cause the CB Code Field to output the number of rows in a field group field. Replace FIELD_NAME with the name of the field group field. Now this just needs to be improved with how much it's going to cost per child. Lets say each child costs $30. Just add to the PHP to multiply it as necessary. Example as follows.
Code:
$children = count( json_decode( '[FIELD_NAME]' ) );
if ( ! $children ) {
return 0;
}
return ( $children * 30 );
This should give you the total child cost. Next just add it as a negative promotion in CBSubs Promotions as a static value with a value of -[FIELD_NAME]. It's important it be negative so it can increase the price and not decrease it.
Based in the screenshot attached, I'd like the subscription cost for this subscription to be set based on the Licence Type Dropdown. i.e. Adults £20 & Juniors U18 £15
So if we have three repeated sections and each related section has a Junior U18 licence type selected this would be a £45 subscription.
I need a running total of the value coming from the LicenceType field
i.e. 3 X Junior U18 Repeats = £45, 3 X Adult Repeats = £60, 2 X Junior U18, and 1 x Adult Repeats = £50
This makes it significantly more complicated. Now you'll need to loop through the JSON data and check against their type so you can adjust the price more accurately. Example as follows.
Code:
$adult = 0;
$junior = 0;
$price = 0;
foreach ( json_decode( '[FIELD_NAME]', true ) as $child ) {
if ( $child['FIELDGROUP_NAME_FIELDTYPE_NAME'] == 'adult' ) {
$adult++;
} elseif ( $child['FIELDGROUP_NAME_FIELDTYPE_NAME'] == 'junior' ) {
$junior++;
}
}
if ( $adult ) {
$price += ( $adult * 20 );
}
if ( $junior ) {
$price += ( $junior * 15 );
}
return $price;
This should give you the total price with adult and junior being different prices. Replace FIELD_NAME with the name of your fieldgroup field (e.g. cb_licenses) and replace FIELDGROUP_NAME_FIELDTYPE_NAME with the name of your type select field name (minus cb_) prefixed with the fieldgroup field name (e.g. cb_licenses_type). Now just do the same as instructed above using a negative promotion to increase the price of a plan.
If you need this actually itemized on their basket it gets even more tricky. Now you'll need a negative promotion for adults and a negative promotion for juniors and 2 code fields per type. Something like the below.
Adult Count Code Field (cb_licenses_adults):
Code:
$adult = 0;
foreach ( json_decode( '[FIELD_NAME]', true ) as $child ) {
if ( $child['FIELDGROUP_NAME_FIELDTYPE_NAME'] == 'adult' ) {
$adult++;
}
}
return $adult;
Adult Price Code Field (cb_licenses_adults_price):
Code:
$adult = 0;
foreach ( json_decode( '[FIELD_NAME]', true ) as $child ) {
if ( $child['FIELDGROUP_NAME_FIELDTYPE_NAME'] == 'adult' ) {
$adult++;
}
}
if ( ! $adult ) {
return 0;
}
return ( $adult * 20 );
Junior Count Code Field (cb_licenses_juniors):
Code:
$junior = 0;
foreach ( json_decode( '[FIELD_NAME]', true ) as $child ) {
if ( $child['FIELDGROUP_NAME_FIELDTYPE_NAME'] == 'junior' ) {
$junior++;
}
}
return $junior;
Junior Price Code Field (cb_licenses_juniors_price):
Code:
$junior = 0;
foreach ( json_decode( '[FIELD_NAME]', true ) as $child ) {
if ( $child['FIELDGROUP_NAME_FIELDTYPE_NAME'] == 'junior' ) {
$junior++;
}
}
if ( ! $junior ) {
return 0;
}
return ( $junior * 15 );
Now in your adult promotion you can use substitutions in the name of a promotion. So you'd have a promotion with a name of "Adults x[cb_licenses_adults]" and a fixed discount of -[cb_licenses_adults_price]. You should now have a plan that dynamically changes its price based off the number of children/adults they provide.