mahmood728
تازه وارد
سلام
بنده تصمیم دارم محتوای قسمتی از سایت رو برای همه محدود کنم و فقط افرادی که محصول خاصی رو خرید کردن بتونن اون محتوای پنها شده رو ببینن.
تو اینترنت گشتم و یک قطعه کدی رو پیدا کردم که این کارو میکرد اما یک مشکلی داشت اونم اینکه وقتیی کسی بصورت پرداخت در محل هم خریدش ثبت می شد اون محتوای پنهان شده رو بهش نشون میداد که خب از لحاظ امنیتی مشکل داره جون اون شخص چولی پرداخت نکرده هنوز.
در واقع کسی که محصول خاصی رو خریده و سفارشش به تکمیل شده تغییر کرده باید بتونه اون محتوای پنهان رو ببینیه.
کد رو برایتون میزارم. از دوستان ممنون می شم اگر این مشکل رو برطرف کنن. ضمنا اگر کسی ووکامرس دولوپر حرفه ای هست پیام بده.
/**
* [wcr_shortcode description]
* @param array pid product id from short code
* @return content shortcode content if user bought product
*/
function wcr_shortcode($atts = [], $content = null, $tag = '')
{
// normalize attribute keys, lowercase
$atts = array_change_key_case((array) $atts, CASE_LOWER);
// start output
$o = '';
// start box
$o .= '<div class="wcr-box">';
$current_user = wp_get_current_user();
if ( current_user_can('administrator') || wc_customer_bought_product($current_user->email, $current_user->ID, $atts['pid'])) {
// enclosing tags
if (!is_null($content)) {
// secure output by executing the_content filter hook on $content
$o .= apply_filters('the_content', $content);
}
} else {
// User doesn't bought this product and not an administator
}
// end box
$o .= '</div>';
// return output
return $o;
}
function wcr_shortcodes_init()
{
add_shortcode('wcr', 'wcr_shortcode');
}
add_action('init', 'wcr_shortcodes_init');
و این کد با شورتکدی بصورت زیر کار میکنه:
بنده تصمیم دارم محتوای قسمتی از سایت رو برای همه محدود کنم و فقط افرادی که محصول خاصی رو خرید کردن بتونن اون محتوای پنها شده رو ببینن.
تو اینترنت گشتم و یک قطعه کدی رو پیدا کردم که این کارو میکرد اما یک مشکلی داشت اونم اینکه وقتیی کسی بصورت پرداخت در محل هم خریدش ثبت می شد اون محتوای پنهان شده رو بهش نشون میداد که خب از لحاظ امنیتی مشکل داره جون اون شخص چولی پرداخت نکرده هنوز.
در واقع کسی که محصول خاصی رو خریده و سفارشش به تکمیل شده تغییر کرده باید بتونه اون محتوای پنهان رو ببینیه.
کد رو برایتون میزارم. از دوستان ممنون می شم اگر این مشکل رو برطرف کنن. ضمنا اگر کسی ووکامرس دولوپر حرفه ای هست پیام بده.
/**
* [wcr_shortcode description]
* @param array pid product id from short code
* @return content shortcode content if user bought product
*/
function wcr_shortcode($atts = [], $content = null, $tag = '')
{
// normalize attribute keys, lowercase
$atts = array_change_key_case((array) $atts, CASE_LOWER);
// start output
$o = '';
// start box
$o .= '<div class="wcr-box">';
$current_user = wp_get_current_user();
if ( current_user_can('administrator') || wc_customer_bought_product($current_user->email, $current_user->ID, $atts['pid'])) {
// enclosing tags
if (!is_null($content)) {
// secure output by executing the_content filter hook on $content
$o .= apply_filters('the_content', $content);
}
} else {
// User doesn't bought this product and not an administator
}
// end box
$o .= '</div>';
// return output
return $o;
}
function wcr_shortcodes_init()
{
add_shortcode('wcr', 'wcr_shortcode');
}
add_action('init', 'wcr_shortcodes_init');
و این کد با شورتکدی بصورت زیر کار میکنه:
کد:
[wcr pid="72"]
This content only show for users that bought product with the id #72
[/wcr]