public static function begin_integration() { if (!self::is_active()) { return false; } if (false === self::$mp_base) { self::$mp_base = self::get_base(); } // General hooks add_action('coursepress_course_created', array(__CLASS__, 'update_product_from_course')); add_action('coursepress_course_updated', array(__CLASS__, 'update_product_from_course')); add_action('coursepress_mp_update_product', array(__CLASS__, 'maybe_create_product')); add_action('post_updated', array(__CLASS__, 'update_course_from_product'), 10, 3); add_filter('coursepress_shortcode_course_cost', array(__CLASS__, 'shortcode_cost'), 10, 2); // Enable Payment Support add_filter('coursepress_offer_paid_courses', array(__CLASS__, 'enable_payment')); // Specific hooks switch (self::$mp_base) { case '3.0': /** * Enroll upon pay * * Reference to order ID, will need to get the actual product using the MarketPress Order class */ add_action('mp_order_order_paid', array(__CLASS__, 'course_paid_3pt0')); /** * Override thumbnail placeholder with course list image. * Note: Typically course products won't have thumbnails, but if a product image is set, this filter * will not override the set product image. */ add_filter('mp_product_image_show_placeholder', array(__CLASS__, 'placeholder_to_course_image'), 10, 2); /** * Return course list image as product image for: `mp_product_images` meta */ add_filter('get_post_metadata', array(__CLASS__, 'course_product_images_meta'), 10, 4); add_filter('mp_order/notification_subject', array(__CLASS__, 'cp_mp_order_notification_subject', 10, 2)); add_filter('mp_order/notification_body', array(__CLASS__, 'cp_mp_order_notification_body', 10, 2)); add_filter('mp_meta/product', array(__CLASS__, 'verify_meta'), 10, 3); add_filter('mp_product/on_sale', array(__CLASS__, 'fix_mp3_on_sale'), 10, 2); // Fix missing MP3.0 meta fields add_filter('wpmudev_field/get_value/sku', array(__CLASS__, 'fix_mp3_sku'), 10, 4); add_filter('wpmudev_field/get_value/regular_price', array(__CLASS__, 'fix_mp3_regular_price'), 10, 4); add_filter('wpmudev_field/get_value/has_sale', array(__CLASS__, 'fix_mp3_has_sale'), 10, 4); add_filter('wpmudev_field/get_value/sale_price[amount]', array(__CLASS__, 'fix_mp3_sale_price_amount'), 10, 4); add_filter('wpmudev_field/get_value/file_url', array(__CLASS__, 'fix_mp3_file_url'), 10, 4); self::$product_ctp = MP_Product::get_post_type(); break; case '2.0': add_action('mp_new_order', array(__CLASS__, 'listen_for_paid_status_for_courses_2pt0')); add_action('mp_order_paid', array(__CLASS__, 'listen_for_paid_status_changes_for_courses_2pt0')); add_filter('mp_order_notification_subject', array(__CLASS__, 'cp_mp_order_notification_subject', 10, 2)); add_filter('mp_order_notification_body', array(__CLASS__, 'cp_mp_order_notification_body', 10, 2)); break; } }
/** * Check whether we're dealing with a product or variation * * @param int $cart_id Cart item ID * * @return bool */ private function _is_product_id($cart_id) { $post = get_post($cart_id); return MP_Product::get_post_type() === $post->post_type; }