awesomemotive / sugarcalendar-core

Sugar Calendar plugin for WordPress
https://wordpress.org/plugins/sugar-calendar-lite/
38 stars 14 forks source link

Allow custom post types with custom taxonomies to work as events #248

Open JiveDig opened 2 years ago

JiveDig commented 2 years ago

Per a discussion with JJJ, this was working at one point but is no longer fully-functional.

A great scenario is using a WooCommerce shop for free/paid events, where the products are the events. This is already working with the following code:

/**
 * Allows WooCommerce Products to work as Sugar Calendar Events.
 * Registers Event Categories to Products.
 *
 * @return void
 */
add_action( 'init', function() {

    // Throws errors.
    // unregister_post_type( 'sc_event' );

    // Enable events on products.
    add_post_type_support( 'product', 'events' );

    // Enable event categories to products.
    register_taxonomy_for_object_type( 'sc_event_category', 'product' );

}, 999 );

This gives us 2 issues:

  1. Custom taxonomy archives (calendars taxonomy, product categories, etc.) all show 0 events/products. The main calendar view does work correctly.
  2. Feeds via the Custom Feeds add-on are all empty. There are no events in them.

After some digging, it looks like the post_type is hard-coded in sugar_calendar_get_event_post_type_id() function. Calendar Feeds add-on uses get_ical_url() function as the core function when generating all feeds, and that function uses sugar_calendar_get_event_post_type_id() to build the feeds from the post type data.

I hard-coded sugar_calendar_get_event_post_type_id() to return product and it didn’t fully work either, though I only tested briefly.

This would be an extremely powerful feature IMO and possibly a nice add-on for full Woo compatibility. It opens a huge door for a powerful paid event management system.

JJJ commented 2 years ago

Improved admin navigation support here: https://github.com/awesomemotive/sugarcalendar-core/commit/5798a18b7fac7310f9109cbee6c64b0042111dab