Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Fairly hacky workaround to a number of common WooTickets issues (WT 1.0.1) - allows the catalog visibility and
- * product type (virtual, downloadable) to be set to desired values automatically.
- *
- * This is not an official Modern Tribe solution and may not even work in all cases - but it may be useful for some
- * folks. No guarantees - drop it in your theme's functions.php file and see what happens ;-)
- *
- * @author Barry Hughes http://codingkills.me
- * @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.txt
- * @date 13 June 2013
- */
- class Adapt_WooTicket_Type {
- protected $trigger_action = 'wp_ajax_tribe-ticket-add-TribeWooTickets';
- protected $final_action = 'set_object_terms'; // Chosen to shoehorn in the final work before the response is dispatched
- protected $ticket_properties = array();
- protected $ticket_id = 0;
- public function __construct(array $properties = null) {
- if (null !== $properties) $this->ticket_properties = $properties;
- add_action($this->trigger_action, array($this, 'listen_for_ticket_creation'), 5);
- add_action($this->final_action, array($this, 'modify_ticket_on_save'));
- }
- public function listen_for_ticket_creation() {
- add_action('save_post', array($this, 'catch_ticket_id'), 10, 2);
- }
- public function catch_ticket_id($post_id, $post) {
- if ('product' !== $post->post_type) return;
- $this->ticket_id = $post_id;
- }
- public function modify_ticket_on_save() {
- if (0 === $this->ticket_id) return;
- foreach ($this->ticket_properties as $key => $value) {
- if (0 !== strpos($key, '_')) $key = "_$key"; // Auto-prefix with the underscore if needed
- update_post_meta($this->ticket_id, $key, $value);
- }
- }
- }
- // Set up the desired product properties - comment out or delete items you
- // don't need/want and add new ones as required
- new Adapt_WooTicket_Type(array(
- 'visibility' => 'visible',
- 'downloadable' => 'yes',
- 'virtual' => 'yes'
- ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement