Jump to content

dynamically change product price/nextduedate during checkout


jimlongo

Recommended Posts

Hi, I want to align the billing cycle of a particular add-on item(s) that I will sell.

There is a nextduedate established by a productA that I sold. I can retrieve that date $dueDate

When I sell product B I want its nextduedate to be set to $dueDate, and its price to be prorated based on that date.

Trying to change price with PreShoppingCartCheckout, and to change the renewal with the ShoppingCartCheckoutCompletePage hook. 

add_hook('PreShoppingCartCheckout', 1, function($vars) {

    $pro_rated_amount = 22.50; // do some math here to get amount

    $command = 'UpdateInvoice';
    $postData = array(
        'invoiceid' => $vars['invoiceid'],
        'subtotal' => $pro_rated_amount,
    );
    $results = localAPI($command, $postData);
});

I think I could change the nextduedate IF i knew the serviceid, which unfortunately is not in $vars.

add_hook( 'ShoppingCartCheckoutCompletePage', 1, function ( $vars ) {

    $next_due_date = nextduedate of productA;

    $command = 'UpdateClientProduct';
    $postData = array(
        'serviceid' => $serviceid,
        'nextduedate' => date('Y-m-d', $next_due_date),
    );
    $results = localAPI($command, $postData);
});


Not sure if this is the best approach.  Open to ideas, if you think this would work, then how would you get the serviceid needed in step2

Edited by jimlongo
Link to comment
Share on other sites

this will change the nextorderdate 

add_hook( 'ShoppingCartCheckoutCompletePage', 1, function ( $vars ) {
	$next_due_date = date('Y-m-d', '1560132772');
	$serviceID = $_SESSION['orderdetails']['ServiceIDs'][0];

    $command = 'UpdateClientProduct';
    $postData = array(
        'serviceid' => $serviceID,
        'nextduedate' => $next_due_date,
    );
    $results = localAPI($command, $postData);
} );

 

But I am not having any luck changing the price.  Not clear if UpdateInvoice inside the PreShoppingCartCheckout hook is the best approach.  So far I have been unable to adjust the amount paid.

 

Edited by jimlongo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated