رفتن به مطلب

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


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

با سلام

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

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

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

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

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

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

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

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

با تشکر

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

سلام میخوای به همه کاربرها ارسال بشه؟ یا دوستان خودت؟

ویرایش شده توسط aghajoon
لینک به ارسال

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


<?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);
?>

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


<?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
لینک به ارسال
این کد برای همه کاربرهای سایت ارسال میکنه اگه بخوای فقط برای دوستان خودت در بادی پرس ارسال بشه باید بجای
 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; } 

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

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

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...