Advertisement
BakerMan

WT 1.0.1: change virtual/downloadable type and visiblity

Jun 13th, 2013
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. /**
  2.  * Fairly hacky workaround to a number of common WooTickets issues (WT 1.0.1) - allows the catalog visibility and
  3.  * product type (virtual, downloadable) to be set to desired values automatically.
  4.  *
  5.  * This is not an official Modern Tribe solution and may not even work in all cases - but it may be useful for some
  6.  * folks. No guarantees - drop it in your theme's functions.php file and see what happens ;-)
  7.  *
  8.  * @author Barry Hughes http://codingkills.me
  9.  * @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.txt
  10.  * @date 13 June 2013
  11.  */
  12. class Adapt_WooTicket_Type {
  13.     protected $trigger_action = 'wp_ajax_tribe-ticket-add-TribeWooTickets';
  14.     protected $final_action = 'set_object_terms'; // Chosen to shoehorn in the final work before the response is dispatched
  15.     protected $ticket_properties = array();
  16.     protected $ticket_id = 0;
  17.  
  18.  
  19.     public function __construct(array $properties = null) {
  20.         if (null !== $properties) $this->ticket_properties = $properties;
  21.         add_action($this->trigger_action, array($this, 'listen_for_ticket_creation'), 5);
  22.         add_action($this->final_action, array($this, 'modify_ticket_on_save'));
  23.     }
  24.  
  25.  
  26.     public function listen_for_ticket_creation() {
  27.         add_action('save_post', array($this, 'catch_ticket_id'), 10, 2);
  28.     }
  29.  
  30.  
  31.     public function catch_ticket_id($post_id, $post) {
  32.         if ('product' !== $post->post_type) return;
  33.         $this->ticket_id = $post_id;
  34.     }
  35.  
  36.  
  37.     public function modify_ticket_on_save() {
  38.         if (0 === $this->ticket_id) return;
  39.  
  40.         foreach ($this->ticket_properties as $key => $value) {
  41.             if (0 !== strpos($key, '_')) $key = "_$key"; // Auto-prefix with the underscore if needed
  42.             update_post_meta($this->ticket_id, $key, $value);
  43.         }
  44.     }
  45. }
  46.  
  47. // Set up the desired product properties - comment out or delete items you
  48. // don't need/want and add new ones as required
  49. new Adapt_WooTicket_Type(array(
  50.     'visibility' => 'visible',
  51.     'downloadable' => 'yes',
  52.     'virtual' => 'yes'
  53. ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement