رفتن به مطلب

ایجاد نوتیفیکیشن سفارشی


پست های پیشنهاد شده

با سلام

من در حال راه اندازی یک وبسایت هستم که در اون از بادی پرس و ووکامرس استفاده شده.

من میخوام یک نوتیفیکیشن سفارشی ایجاد کنم ، به این صورت که هر زمان که محصولی به فروشگاه اضافه میشه برای کاربران،یک نوتیفیکیشن مثل نوتیفیکیشن های دیگه بادی پرس ظاهر بشه

مقالات زیادی رو هم خوندم اما حقیقتا متوجه نشدم

کسی میتونه راهنمایی کنه؟

این هم لیست مقالات

http://androoha.com/...s-buddypress-en

http://stackoverflow...n-in-buddypress

https://buddypress.o...-notifications/

با تشکر

ویرایش شده توسط aryamehraboon
لینک به ارسال
  • 3 هفته بعد...

سلام این کد برای همه کاربرها ارسال میکنه اما اگر بخواهی فقط برای دوستان خودت ارسال بشه باید یک تغییراتی درش ایجاد بشه شاید بتونم به عنوان پلاگین در مخزن وردپرس قرارش بدم


<?php
/*
Plugin Name: BP notification woocommerce
Plugin URI: http://webcaffe.ir
Description: Send notification buddypress for all member when publish woocommerce product .
Version: 0.1
Author: asghar hatampoor
Author URI: http://webcaffe.ir
*/
define("BP_PRODUCT_NOTIFIER_SLUG","pro_notification");
function bp_product_setup_globals() {
global $bp, $current_blog;
$bp->bp_product=new stdClass();
$bp->bp_product->id = 'bp_product';
$bp->bp_product->slug = BP_PRODUCT_NOTIFIER_SLUG;
$bp->bp_product->notification_callback = 'product_format_notifications_webcaffe';//show the notification
$bp->active_components[$bp->bp_product->id] = $bp->bp_product->id;

do_action( 'bp_product_setup_globals' );
}
add_action( 'bp_setup_globals', 'bp_product_setup_globals' );
function product_send_notification_webcaffe($id){
global $bp, $wpdb;
$savedPost = get_post($id);
if($savedPost->post_status == "publish" && $savedPost->post_type=="product" && !wp_is_post_revision($id)){

foreach( $wpdb->get_col( "SELECT ID FROM $wpdb->users" ) as $user_id):
bp_core_add_notification($savedPost->ID, $user_id , $bp->bp_product->id, 'new_product_'.$savedPost->ID, $savedPost->post_author);
endforeach;

}
}
add_action('save_post','product_send_notification_webcaffe');
function product_format_notifications_webcaffe( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
do_action( 'product_format_notifications_webcaffe', $action, $item_id, $secondary_item_id, $total_items, $format );
$createdPost = get_post($item_id);
$creator = get_userdata($secondary_item_id);
$text = '</a> <div id="'.$action.'"class="notification">'.
__("There is a new product ", "bp-product").'
<a class="ab-item" title="'.$createdPost->post_title.'"href="'.get_permalink( $item_id ).'"> '.__("check it out!", "bp-product").'
</a>
</div>';
return $text;
}
function product_remove_notification_webcaffe($savedPost){
global $bp;
$savedPost = get_post($id);
$user_id=$bp->loggedin_user->id;
$item_id=$_POST['item_id'];
$component_name='bp_product';
$component_action='new_product_'.$savedPost->ID;
bp_core_delete_notifications_by_item_id ($user_id, $item_id, $component_name, $component_action);
}
add_action('woocommerce_single_product_summary','product_remove_notification_webcaffe',10,2);
?>

  • امتیاز 2
لینک به ارسال
سلام این کد برای همه کاربرها ارسال میکنه اما اگر بخواهی فقط برای دوستان خودت ارسال بشه باید یک تغییراتی درش ایجاد بشه شاید بتونم به عنوان پلاگین در مخزن وردپرس قرارش بدم


<?php
/*
Plugin Name: BP notification woocommerce
Plugin URI: http://webcaffe.ir
Description: Send notification buddypress for all member when publish woocommerce product .
Version: 0.1
Author: asghar hatampoor
Author URI: http://webcaffe.ir
*/
define("BP_PRODUCT_NOTIFIER_SLUG","pro_notification");
function bp_product_setup_globals() {
global $bp, $current_blog;
$bp->bp_product=new stdClass();
$bp->bp_product->id = 'bp_product';
$bp->bp_product->slug = BP_PRODUCT_NOTIFIER_SLUG;
$bp->bp_product->notification_callback = 'product_format_notifications_webcaffe';//show the notification
$bp->active_components[$bp->bp_product->id] = $bp->bp_product->id;

do_action( 'bp_product_setup_globals' );
}
add_action( 'bp_setup_globals', 'bp_product_setup_globals' );
function product_send_notification_webcaffe($id){
global $bp, $wpdb;
$savedPost = get_post($id);
if($savedPost->post_status == "publish" && $savedPost->post_type=="product" && !wp_is_post_revision($id)){

foreach( $wpdb->get_col( "SELECT ID FROM $wpdb->users" ) as $user_id):
bp_core_add_notification($savedPost->ID, $user_id , $bp->bp_product->id, 'new_product_'.$savedPost->ID, $savedPost->post_author);
endforeach;

}
}
add_action('save_post','product_send_notification_webcaffe');
function product_format_notifications_webcaffe( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
do_action( 'product_format_notifications_webcaffe', $action, $item_id, $secondary_item_id, $total_items, $format );
$createdPost = get_post($item_id);
$creator = get_userdata($secondary_item_id);
$text = '</a> <div id="'.$action.'"class="notification">'.
__("There is a new product ", "bp-product").'
<a class="ab-item" title="'.$createdPost->post_title.'"href="'.get_permalink( $item_id ).'"> '.__("check it out!", "bp-product").'
</a>
</div>';
return $text;
}
function product_remove_notification_webcaffe($savedPost){
global $bp;
$savedPost = get_post($id);
$user_id=$bp->loggedin_user->id;
$item_id=$_POST['item_id'];
$component_name='bp_product';
$component_action='new_product_'.$savedPost->ID;
bp_core_delete_notifications_by_item_id ($user_id, $item_id, $component_name, $component_action);
}
add_action('woocommerce_single_product_summary','product_remove_notification_webcaffe',10,2);
?>

شما یدونه باشی :)

امتحان میکنم خبر میدم

لینک به ارسال

این کد برای همه کاربرهای سایت ارسال میکنه اگه بخوای فقط برای دوستان خودت در بادی پرس ارسال بشه باید بجای


if($savedPost->post_status == "publish" && $savedPost->post_type=="product" && !wp_is_post_revision($id)){

foreach( $wpdb->get_col( "SELECT ID FROM $wpdb->users" ) as $user_id):
bp_core_add_notification($savedPost->ID, $user_id , $bp->bp_product->id, 'new_product_'.$savedPost->ID, $savedPost->post_author);
endforeach;

}

این کد را قرار بدی


if(function_exists("friends_get_friend_user_ids") && $savedPost->post_status == "publish" && $savedPost->post_type=="product" && !wp_is_post_revision($id) ){
$friends = friends_get_friend_user_ids($savedPost->post_author);
foreach($friends as $friend):
bp_core_add_notification($savedPost->ID, $friend , $bp->bp_product->id, 'new_product_'.$savedPost->ID, $savedPost->post_author);
endforeach;

}

پلاگینش را کامل کردم که عکس محصول هم نمایش میده و دارای فایل زبان هم هست برای وردپرس ارسال کردم اگه قبول شد لینکش را اینجا میذارم

ویرایش شده توسط aghajoon
  • امتیاز 1
لینک به ارسال
این کد برای همه کاربرهای سایت ارسال میکنه اگه بخوای فقط برای دوستان خودت در بادی پرس ارسال بشه باید بجای
 if($savedPost->post_status == "publish" && $savedPost->post_type=="product" && !wp_is_post_revision($id)){ foreach( $wpdb->get_col( "SELECT ID FROM $wpdb->users" ) as $user_id): bp_core_add_notification($savedPost->ID, $user_id , $bp->bp_product->id, 'new_product_'.$savedPost->ID, $savedPost->post_author); endforeach; } 

این کد را قرار بدی

 if(function_exists("friends_get_friend_user_ids") && $savedPost->post_status == "publish" && $savedPost->post_type=="post" && !wp_is_post_revision($id) ){ $friends = friends_get_friend_user_ids($savedPost->post_author); foreach($friends as $friend): bp_core_add_notification($savedPost->ID, $friend , $bp->bp_product->id, 'new_product_'.$savedPost->ID, $savedPost->post_author); endforeach; } 

پلاگینش را کامل کردم که عکس محصول هم نمایش میده و دارای فایل زبان هم هست برای وردپرس ارسال کردم اگه قبول شد لینکش را اینجا میذارم

عالیه ، موفّق باشی

  • امتیاز 1
لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...