$name, 'available' => $available, ); if ( ! tinv_get_option( 'integrations', $slug ) ) { return; } if ( ! $available ) { return; } // myCred hooks if ( defined( 'myCRED_VERSION' ) ) { /** * Register MyCred hook for the WooCommerce Wishlist. * * @param array $installed The list of installed MyCred hooks. * * @return array The updated list of installed MyCred hooks. */ function tinvwl_mycred_register_ti_woocommerce_wishlist_hook( array $installed ): array { $installed['tinvwl'] = array( 'title' => __( 'WooCommerce Wishlist', 'ti-woocommerce-wishlist' ), 'description' => __( 'Awards %_plural% for users adding products to their wishlist and purchased products from their wishlist.', 'ti-woocommerce-wishlist' ), 'callback' => array( 'myCRED_Hook_TinvWL' ), ); return $installed; } add_filter( 'mycred_setup_hooks', 'tinvwl_mycred_register_ti_woocommerce_wishlist_hook', 100 ); /** * Load MyCred hook for the WooCommerce Wishlist. */ function tinvwl_mycred_load_ti_woocommerce_wishlist_hook() { // If the hook has been replaced or if the plugin is not installed, exit now. if ( class_exists( 'myCRED_Hook_TinvWL' ) ) { return; } class myCRED_Hook_TinvWL extends myCRED_Hook { /** * Constructor. * * @param array $hook_prefs The hook preferences. * @param string $type The point type to use. */ public function __construct( $hook_prefs, $type = MYCRED_DEFAULT_TYPE_KEY ) { parent::__construct( array( 'id' => 'tinvwl', 'defaults' => array( 'tinvwl_added' => array( 'creds' => 1, 'log' => '%plural% for adding a product to a wishlist', 'limit' => '0/x', ), 'tinvwl_purchased' => array( 'creds' => 1, 'log' => '%plural% for purchasing a product from a wishlist', 'limit' => '0/x', ), ), ), $hook_prefs, $type ); } /** * Run the hook. */ public function run() { add_action( 'tinvwl_product_added', array( $this, 'added' ) ); add_action( 'tinvwl_product_purchased', array( $this, 'purchased' ), 10, 3 ); } /** * Award points to the user who added a product to their wishlist. * * @param array $data Product data, including author and wishlist IDs. */ public function added( $data ) { // Must be logged in if ( ! is_user_logged_in() ) { return; } $user_id = get_current_user_id(); // Award the user adding to wishlist if ( $this->prefs['tinvwl_added']['creds'] !== 0 && ! $this->core->exclude_user( $user_id ) ) { // Limit if ( ! $this->over_hook_limit( 'tinvwl_added', 'added_to_wishlist', $user_id ) ) { // Make sure this is unique event if ( ! $this->core->has_entry( 'added_to_wishlist', $data['product_id'], $user_id ) ) { // Execute $this->core->add_creds( 'added_to_wishlist', $user_id, $this->prefs['tinvwl_added']['creds'], $this->prefs['tinvwl_added']['log'], $data['product_id'], array( 'ref_type' => 'post' ), $this->mycred_type ); } } } } /** * Award points to user who purchased a product from a wishlist. * * @param WC_Order $order Order object. * @param WC_Order_Item_Product $item Order item product object. * @param array $wishlist A wishlist data where product added from. */ public function purchased( $order, $item, $wishlist ) { // Must be logged in if ( ! is_user_logged_in() ) { return; } $user_id = get_current_user_id(); // Award the user adding to wishlist if ( $this->prefs['tinvwl_purchased']['creds'] !== 0 && ! $this->core->exclude_user( $user_id ) ) { // Limit if ( ! $this->over_hook_limit( 'tinvwl_purchased', 'purchased_from_wishlist', $user_id ) ) { // Make sure this is a unique event if ( ! $this->core->has_entry( 'purchased_from_wishlist', $item->get_id(), $user_id ) ) { // Execute $this->core->add_creds( 'purchased_from_wishlist', $user_id, $this->prefs['tinvwl_purchased']['creds'], $this->prefs['tinvwl_purchased']['log'], $item->get_id(), array( 'ref_type' => 'post' ), $this->mycred_type ); } } } } /** * Preferences */ public function preferences() { $prefs = $this->prefs; ?>