Redirect in checkout for only one product

  • Posts: 49
  • Thank you received: 0
8 years 4 months ago #245899

-- HikaShop version -- : 2.6.3

Hi,

I would like to create a redirect to a landing page in checkout, but I want it to only apply to one product. In other words, I do not want the redirect on any other product other than a product I choose. How may I do this?

Thank you for your kind attention.

Please Log in or Create an account to join the conversation.

  • Posts: 4753
  • Thank you received: 644
  • MODERATOR
8 years 4 months ago #245903

Hello,

Can precise your idea please ?
You mean create a button link to checkout in only one product page ? OR only have a redirection (with add to cart button) in checkout for one product and not other ?
More precisely, does have a button (add to cart button) with another text like "Go to checkout" AND the automatic redirection to checkout (thanks to the "After a product is added to the cart" option) only in one product page, can be for you a good solution ?

Awaiting news from you.

Regards

Last edit: 8 years 4 months ago by Philip.

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 0
8 years 4 months ago #245974

Hi Phillipe,

I want the redirect to occur when customers press "finish" and they also have that specific product in their cart. In other words, if they have the product "Content Marketing for Social Media" in their cart and they buy it, I want a redirect to a landing page to occur. But I only want the redirect if this specific product is in the cart. If there are other products in the cart, but not this product, I do not want a redirect.

I hope this is clearer.

Also can you tell me how to get rid of the "Additional Information" section (you can see it in the attachment)? I only sell digital products and don't need comments or delivery date in my order form. I look forward to your help. Thank you.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
8 years 4 months ago #245989

Hello,

1. There is actually no option to do it and it will require some code customization if you want your customers to be redirected :
- After pressing "Finish" then you'll have to edit the code of your Payment plugins
- After they reach the thank you page, then you'll have to directly edit the code of the "after_end" file of the "checkout" view of your front-end template via "Hikashop->Display->Views."

2. To remove the "Additional Information" section you'll have to remove the "Field" action from your checkout workflow via "Hikashop->System->Configuration->Checkout".

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 0
8 years 4 months ago #246042

Is there any code I can implement to redirect after they reach the thank you page only when they have one specific item in their cart. In other words, if the customer only has "Content Marketing for Social Media" and no other product, how do I redirect after they reach the thank you page only for this scenario and no other scenario?

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
8 years 4 months ago #246075

You'll have to edit the file "after_end" and add your custom code there.

There, you can loop through the products of the order in $this->order->products and check their ID or code or name and then do a Joomla redirect:
snipt.net/esedic/how-to-redirect-using-the-joomla-api/

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 0
8 years 4 months ago #246152

Hi Nicolas,

Can you give me a sample code for "$this->order->products"? Where does the product ID go?

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
8 years 4 months ago #246167

Hi,

It's simple standard PHP to loop through an array of elements. For example:

foreach($this->order->products as $product){
 if($product->product_id == XXX){
  //do stuff
 }
}

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 0
8 years 4 months ago #246272

Hi Nicolas,

I'm sorry to bother you, but where do I find the product ID?

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
8 years 4 months ago #246281

Hi,

It's in that variable: $product->product_id
You can see it in the URL when you edit a product.
But you can do the check on the product_code instead if you want. It will work the same and you already know them.

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 0
8 years 4 months ago #246397

Hi Nicolas,

Thank you for your help so far. Unfortunately, I do not know PHP. Can you please tell me if there is anything wrong with the code below?

//Custom Hikashop PHP code below
foreach($this->order->products as $product){
 if($product->product_code == CMSM1){
  $app=& JFactory::getApplication();
$app->redirect('https://classdigitalau.leadpages.co/thank-you-for-downloading/');
 }
}

Thank you again for helping me.

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
8 years 4 months ago #246399

Hi,

You need to write 'CMSM1' not just CMSM1.
The rest looks fine.

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 0
8 years 4 months ago #246445

Hi Nicolas,

I've made the change, but the redirect isn't working. Nothing happens. Can you help me figure out what's wrong?

The full code to be debugged is below:

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.6.3
 * @author	hikashop.com
 * @copyright	(C) 2010-2016 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
$app = JFactory::getApplication();
$app->enqueueMessage( JText::_('THANK_YOU_FOR_PURCHASE') );
//Custom Hikashop PHP code below
foreach($this->order->products as $product){
 if($product->product_code == 'CMSM1'){
  $app=& JFactory::getApplication();
$app->redirect('https://classdigitalau.leadpages.co/thank-you-for-downloading/');
 }
}

Last edit: 8 years 4 months ago by Clarenceljw. Reason: Update

Please Log in or Create an account to join the conversation.

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
8 years 4 months ago #246492

Hi,

Try with :
if($product->order_product_code == 'CMSM1'){
instead of:
if($product->product_code == 'CMSM1'){

The following user(s) said Thank You: Clarenceljw

Please Log in or Create an account to join the conversation.

  • Posts: 49
  • Thank you received: 0
8 years 4 months ago #246499

Hi Nicolas,

It works now! Thank you!

Please Log in or Create an account to join the conversation.

Time to create page: 0.087 seconds
Powered by Kunena Forum