bbdev

Buddyboss Marketplace - change favorite icon

Jun 24th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. add_action('woocommerce_after_shop_loop_item', 'myprefix_bm_product_to_favorites', 8 );
  2. add_action('woocommerce_after_add_to_cart_form', 'myprefix_bm_product_to_favorites', 9 );
  3. function myprefix_bm_product_to_favorites() {
  4.     if( !function_exists( 'buddyboss_bm' ) )
  5.         return;
  6.    
  7.     $obj = buddyboss_bm();
  8.     remove_action('woocommerce_after_shop_loop_item', array( $obj, 'bm_product_to_favorites' ), 9 );
  9.     remove_action('woocommerce_after_add_to_cart_form', array( $obj, 'bm_product_to_favorites' ) );
  10.    
  11.     $product_id = get_the_ID();
  12.     $vendor_id      = WCV_Vendors::get_vendor_from_product( $product_id );
  13.     $current_user = bp_loggedin_user_id();
  14.     if($current_user && $current_user != $vendor_id) {
  15.         $favorites = get_user_meta($current_user, "favorite_products", true);
  16.         $class = (is_array($favorites) && in_array($product_id, $favorites)) ? ' favorited' : '';
  17.         $tooltip = __('Add to Favorites', 'buddyboss-marketplace');
  18.         if($class) {
  19.             $tooltip = __('Remove from Favorites', 'buddyboss-marketplace');
  20.         }
  21.         echo '<a href="#" class="boss-tooltip bm-product-to-favorites ' . $class . '" data-tooltip="'.$tooltip.'" data-id="' . $product_id . '"><i class="fa fa-thumbs-up"></i></a>';
  22.     }
  23. }
Add Comment
Please, Sign In to add comment