Jump to content

Recommended Posts

I have used the debug tag and found variable outputs but I require one for product ID or name and the number of items purchased. How can I gather this information for rendering on the complete.tpl ? 

 

Edited by UWH - David

Share this post


Link to post
Share on other sites
7 hours ago, UWH - David said:

I have used the debug tag and found variable outputs but I require one for product ID or name and the number of items purchased. How can I gather this information for rendering on the complete.tpl ?

if the information you want isn't directly available (or inferred) from the Smarty variables, then you may need to use an action hook to obtain it - two spring to mind, "AfterShoppingCartCheckout" and "ShoppingCartCheckoutCompletePage" - from your description of what you want, I think the AfterShoppingCartCheckout hook will be the more appropriate, but you may still need to query the db for additional details if they're not directly provided by the hook variables.

 

Share this post


Link to post
Share on other sites
13 hours ago, brian! said:

if the information you want isn't directly available (or inferred) from the Smarty variables, then you may need to use an action hook to obtain it - two spring to mind, "AfterShoppingCartCheckout" and "ShoppingCartCheckoutCompletePage" - from your description of what you want, I think the AfterShoppingCartCheckout hook will be the more appropriate, but you may still need to query the db for additional details if they're not directly provided by the hook variables.

 

It seems using php hooks are not going through the .tpl file. How would this be performed?

Share this post


Link to post
Share on other sites

From WHMCS Settings: 

Tick to allow use of the Smarty {php} tag in templates. This is considered a security risk. 
Enabled 

*Looks like I am creating a .php in /includes/hooks/

Edited by UWH - David

Share this post


Link to post
Share on other sites

Unfortunately, this hook file doesn't seem to be working. I must be missing something simple:

<?php
add_hook('CartTotalAdjustment', 1, function ($vars)
{
    $productid = $vars['pid'];

});

add_hook('AfterShoppingCartCheckout', 1, function ($vars)
{
    $serviceids = $vars['ServiceIDs'];

});

complete.tpl

list={$serviceids}{$productid}

Gives me a blank output, list=

 

Share this post


Link to post
Share on other sites
12 hours ago, UWH - David said:

From WHMCS Settings: 

Tick to allow use of the Smarty {php} tag in templates. This is considered a security risk. 
Enabled 

*Looks like I am creating a .php in /includes/hooks/

as a general rule, you should never need to use {php} in templates.

11 hours ago, UWH - David said:

Unfortunately, this hook file doesn't seem to be working. I must be missing something simple:

I couldn't get it working on v7.4.1 either - so I must be missing it too. :roll:

if you had to, you could use ClientAreaPageCart as a means of querying the db and passing the results back to the template...

<?php

# After Shopping Cart Checkout Hook
# Written by brian!

function complete_page_hook($vars){
	
	if ($vars['templatefile'] == 'complete'){
		$invoiceid = $vars['invoiceid'];
	}
	return array("brian" => $invoiceid);
}
add_hook("ClientAreaPageCart", 1, "complete_page_hook");

the above hook is practically useless, as it will take the invoiceID value from the template, assign it to a variable $brian and pass it back for you to use in the template {$brian) - but it at least shows you that you can grab the invoiceID or orderID from the template and with that, you can query the db and get the information you need.

also, remember that the complete.tpl page still has access to the cart session variables/arrays - so to get a count of products in the order, you can use the following Smarty in the template...

{$smarty.session.orderdetails.Products|@count}

and you can get similar counts for Domains, Addons & Renewals by replacing "Products" in the above code (which you could add together for a grand total).

these are arrays, so you can access their contents in Smarty, but the products array will only give you serviceIDs (the id value for the order from tblhosting), it won't directly give you product IDs or names - to get that, you'd have to query the database via a hook.

Share this post


Link to post
Share on other sites
10 hours ago, brian! said:

as a general rule, you should never need to use {php} in templates.

I couldn't get it working on v7.4.1 either - so I must be missing it too. :roll:

if you had to, you could use ClientAreaPageCart as a means of querying the db and passing the results back to the template...

<?php

# After Shopping Cart Checkout Hook
# Written by brian!

function complete_page_hook($vars){
	
	if ($vars['templatefile'] == 'complete'){
		$invoiceid = $vars['invoiceid'];
	}
	return array("brian" => $invoiceid);
}
add_hook("ClientAreaPageCart", 1, "complete_page_hook");

the above hook is practically useless, as it will take the invoiceID value from the template, assign it to a variable $brian and pass it back for you to use in the template {$brian) - but it at least shows you that you can grab the invoiceID or orderID from the template and with that, you can query the db and get the information you need.

also, remember that the complete.tpl page still has access to the cart session variables/arrays - so to get a count of products in the order, you can use the following Smarty in the template...

{$smarty.session.orderdetails.Products|@count}

and you can get similar counts for Domains, Addons & Renewals by replacing "Products" in the above code (which you could add together for a grand total).

these are arrays, so you can access their contents in Smarty, but the products array will only give you serviceIDs (the id value for the order from tblhosting), it won't directly give you product IDs or names - to get that, you'd have to query the database via a hook.

This is very intriguing. From what was ordered, how would you go about getting a or the package IDs from that?

Share this post


Link to post
Share on other sites
12 hours ago, UWH - David said:

This is very intriguing. From what was ordered, how would you go about getting a or the package IDs from that?

from the session, you can't - not without querying the database.... which you could do with {php} tags in the template, but i've already rightly told you not to go down that road, so you're left with hooks.

<?php

# Shopping Cart Complete Page Output Hook
# Written by brian!

use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ShoppingCartCheckoutCompletePage', 1, function($vars) {
	
	$orderID = $vars['orderid'];
	$myproducts = Capsule::table('tblhosting')
				->join('tblproducts', 'tblhosting.packageid', '=', 'tblproducts.id')
				->where('orderid',$orderID)
				->pluck('tblhosting.packageid','tblproducts.name');

	$output = 'The Following Products (Names & IDs) have been ordered<br>';
	
	foreach ($myproducts as $name => $id) {
		$output .= $name . ' -> ' . $id.'<br>';
	}
	
    return $output;
});

sMlJmSD.png

the above hook will give you a list of Product Names (and their package IDs) in the order and output it on the complete.tpl template - i've not added any html layout code or css to it, nor have I used language strings, but you can add them to $output if required.

btw - I assume you'd only need name or ID as the client won't need to know both... also, bear in mind, this example just covers products, you'd have to expand it to check for domains, addons etc.

alternatively, you could use the invoiceID value, and search the invoiceitems table to get a list of line items of the order and output that instead (or in addition to).

your best bet is to think clearly about what information you want and how you want to output it - then work out the best (simplest/quickest) way to get that information to the template.

9 hours ago, UWH - David said:

I would pay for consulting at this point to get this figured out. 

then you'd either need to post in Service Offers & Requests and get quotes from developers, or contact a developer directly by PM... but to do that last step, you'd need to enable Private Messaging in your profile settings! :idea:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By luigidelgado
      For all of you (like me) who are looking for or simply just would like to have a List of all Email Templates Variables Available when designing your email templates, my 2 cents:
       
       
      Client Related
      ID {$client_id}
      Client Name {$client_name}
      First Name {$client_first_name}
      Last Name {$client_last_name}
      Company Name {$client_company_name}
      Email Address {$client_email}
      Address 1 {$client_address1}
      Address 2 {$client_address2}
      City {$client_city}
      State/Region {$client_state}
      Postcode {$client_postcode}
      Country {$client_country}
      Phone Number {$client_phonenumber}
      Password {$client_password}
      Signup Date {$client_signup_date}
      Credit Balance {$client_credit}
      Card Type {$client_cc_type}
      Card Last 4 {$client_cc_number}
      Expiry Date {$client_cc_expiry}
      Remote Gateway Token {$client_gateway_id}
      Client Group ID {$client_group_id}
      Client Group Name {$client_group_name}
      Total Due Invoices Balance {$client_due_invoices_balance}
      Custom Fields (Array) {$client_custom_fields.1}
      Status {$client_status}
       
       
      Product/Service Related
      Order ID {$service_order_id}
      ID {$service_id}
      Signup Date {$service_reg_date}
      Product Name {$service_product_name}
      Product Description {$service_product_description}
      Domain {$service_domain}
      Config. Options {$service_config_options}
      Server Name {$service_server_name}
      Server Hostname {$service_server_hostname}
      Server IP {$service_server_ip}
      Dedicated IP {$service_dedicated_ip}
      Assigned IPs {$service_assigned_ips}
      Nameserver 1 {$service_ns1}
      Nameserver 2 {$service_ns2}
      Nameserver 3 {$service_ns3}
      Nameserver 4 {$service_ns4}
      Nameserver 1 IP {$service_ns1_ip}
      Nameserver 2 IP {$service_ns2_ip}
      Nameserver 3 IP {$service_ns3_ip}
      Nameserver 4 IP {$service_ns4_ip}
      Payment Method {$service_payment_method}
      First Payment Amount {$service_first_payment_amount}
      Recurring Payment {$service_recurring_amount}
      Billing Cycle {$service_billing_cycle}
      Next Due Date {$service_next_due_date}
      Status {$service_status}
      Suspend Reason {$service_suspension_reason}
      Cancellation Type {$service_cancellation_type}
      Username {$service_username}
      Password {$service_password}
      Custom Fields (Array) {$service_custom_fields.1}
       
       
      Domain Related
      Order ID {$domain_order_id}
      Signup Date {$domain_reg_date}
      Domain {$domain_name}
      SLD (yourdomain) {$domain_sld}
      TLD (com) {$domain_tld}
      Reg Period {$domain_reg_period}
      First Payment Amount {$domain_first_payment_amount}
      Recurring Amount {$domain_recurring_amount}
      Next Due Date {$domain_next_due_date}
      Expiry Date {$domain_expiry_date}
      Registrar {$domain_registrar}
       
      'Days Until Expiry' and 'Days Until Next Due' will show 0 if the date has passed.
      'Days After Expiry' and 'Days After Next Due' should be used if the date has passed.
      Days Until Expiry {$domain_days_until_expiry}
      Days Until Next Due {$domain_days_until_nextdue}
       
      'Days After Expiry' and 'Days After Next Due' will only be defined if the date has passed.
      Days After Expiry {$domain_days_after_expiry}
      Days After Next Due {$domain_days_after_nextdue}
      Status {$domain_status}
      DNS Management {$domain_dns_management}
      Email Forwarding {$domain_email_forwarding}
      ID Protection {$domain_id_protection}
      Auto Renew Disabled {$domain_do_not_renew}
       
       
      Support Ticket Related
      ID {$ticket_id}
      Department {$ticket_department}
      Date Opened {$ticket_date_opened}
      Subject {$ticket_subject}
      Message {$ticket_message}
      Status {$ticket_status}
      Priority {$ticket_priority}
      Ticket URL {$ticket_url}
      Ticket Link {$ticket_link}
      Auto Close Time {$ticket_auto_close_time}
      Knowledgebase Auto Suggestions {$ticket_kb_auto_suggestions}
       
       
      Invoice Related
      Invoice ID {$invoice_id}
      Invoice # {$invoice_num}
      Date Created {$invoice_date_created}
      Due Date {$invoice_date_due}
      Date Paid {$invoice_date_paid}
      Invoice Items (Array) {$invoice_items}
      Invoice Items HTML {$invoice_html_contents}
      Sub Total {$invoice_subtotal}
      Tax {$invoice_tax}
      Tax Rate {$invoice_tax_rate}
      Credit {$invoice_credit}
      Total {$invoice_total}
      Amount Paid {$invoice_amount_paid}
      Balance {$invoice_balance}
      Last Payment Amount {$invoice_last_payment_amount}
      Last Payment Trans ID {$invoice_last_payment_transid}
      Payment Method {$invoice_payment_method}
      Payment Link {$invoice_payment_link}
      Subscription ID {$invoice_subscription_id}
      Status {$invoice_status}
      Invoice Link {$invoice_link}
      Previous Balance {$invoice_previous_balance}
      Total Due Invoices Balance {$invoice_total_balance_due}
      Notes {$invoice_notes}
       
       
      Other
      Company Name {$company_name}
      Domain {$company_domain}
      Logo URL {$company_logo_url}
      WHMCS URL {$whmcs_url}
      WHMCS Link {$whmcs_link}
      WHMCS Admin URL {$whmcs_admin_url}
      WHMCS Admin Link {$whmcs_admin_link}
      Marketing Unsubscribe URL {$unsubscribe_url}
      Signature {$signature}
      Full Sending Date {$date}
      Full Sending Time {$time}
       
       
      Conditional Display
      You can use conditionals to display text based on other values - for example:
       
      {if $ticket_department eq "Sales"}
      Sales only operates Monday-Friday 9am-5pm
      {else}
      Your ticket has been received and will be answered shortly
      {/if}
       
      Looping through data
      A foreach loop can be used to cycle through values like invoice items:
       
      {foreach from=$array_data item=data}
      {$data.option}: {$data.value}
      {/foreach}
    • By t-chan
      Guys,
       
       
      Please what are WHMCS $email [customer & non-customer] , $product_ids and $product_names global variable that one can use with Facebook Pixel?
       
       
      For an example, these are purchase variables for:
       
       
      Shopify:

      '{{ total_price | money_without_currency }}','currency':'USD'
       
      Magento:

      <?php echo $amount; ?>
       
      WooCommerce:

      <?php echo $order->get_order_total(); ?>
       
      Squarespace:

      {orderGrandTotal}
       
      BigCommerce:

      %%ORDER_SUBTOTAL%%;
       
      Thanks
  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines