Change status of an entry after purchase

If you would like to create a system where a custom can pay for a weblog entry (basically as an advertisement) you can use the standard Purchased Items weblog as that advertisement entry by adding custom data to purchased items. If you would prefer to have a little more control, or a variety of different weblogs used to store customer created weblog entries, CartThrob can accommodate that as well.

Let users create and edit their entry via EE’s standard Stand Alone Entry Form, set the default status to “closed” or whatever you prefer. Once they’ve created their entry, create an add_to_cart_form and sell the entry to your customer. Upon completion of the transaction, you can add code to the on_authorize.php file located here:

system/modules/cartthrob/process/cartthrob.on_authorize.php

to convert the status of that order to something like “open”. Using statuses, you can use a standard weblog entries loop to display those purchased entries.

{examples_channel_configuration}

{/examples_channel_configuration}
<?php
// Add code here that you would like to be parsed upon confirmation of authorization.

// $this refers to an instance of mod.cartthrob.php
global $FNS, $TMPL, $IN, $REGX, $PREFS, $DB;

foreach ($this->_get_cart_items() as $row_id => $item) {
  // Each item's original entry_id is in $item['entry_id']
  $entry_id = $item['entry_id'];
  $data = array('status' => 'Open');
  $sql = $DB->update_string('exp_weblog_titles', $data, "entry_id = '$entry_id'");
  $DB->query($sql);
}

Using the purchased items weblog is a simpler method, but does not offer as much flexibility as this method. Though this method is a little more complex if offers you a great amount of power and control.

Top of Page