Showing posts with label role. Show all posts
Showing posts with label role. Show all posts

Thursday, 6 October 2022

SHORTCODE Content Base on User Role/ User Log in

function member_only_shortcode($atts, $content = null) { if (is_user_logged_in() && !is_null($content) && !is_feed()) { return $content; } } add_shortcode('member_only', 'member_only_shortcode');
[member_only]User is logged in.[/member_only]

Monday, 8 March 2021

WP Functions : Minimum Order By User Role

 add_action( 'woocommerce_check_cart_items', 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
    // minimum order value by user role
    if ( current_user_can('distributor_prices') )
        $minimum = 3000; 
    elseif ( current_user_can('wholesale_prices') )
        $minimum = 1000;
    elseif ( current_user_can('wholesale_vat_exc') )
        $minimum = 600;
    else 
        $minimum = 300; // default
    if ( WC()->cart->subtotal < $minimum ) {
        if( is_cart() ) {
            wc_print_notice( sprintf( 
                'You must have an order with a minimum of %s to place your order, your current order total is %s.' , 
                wc_price( $minimum ), 
                wc_price( WC()->cart->subtotal )
            ), 'error' );
        } else {
            wc_add_notice( sprintf( 
                'You must have an order with a minimum of %s to place your order, your current order total is %s.' , 
                wc_price( $minimum ), 
                wc_price( WC()->cart->subtotal )
            ), 'error' );
        }
    }
}

//////////===================!-_-!===================== /////////

add_action( 'woocommerce_check_cart_items', 'required_min_cart_subtotal_amount' );
function required_min_cart_subtotal_amount() {

    // HERE Set minimum cart total amount
    $minimum_amount = 250;

    // Total (before taxes and shipping charges)
    $cart_subtotal = WC()->cart->subtotal;

    // Add an error notice is cart total is less than the minimum required
    if( $cart_subtotal < $minimum_amount  ) {
        // Display an error message
        wc_add_notice( '<strong>' . sprintf( __("A minimum total purchase amount of %s is required to checkout."), wc_price($minimum_amount) ) . '<strong>', 'error' );
    }
}

Saturday, 5 September 2020

If current User (Role) Execute Code

<?php if( current_user_can('editor') || current_user_can('administrator') ) { 

    // Stuff here for administrators or editors

} ?>

Sunday, 1 April 2018

PHP Wp : Only Declare Role can view content div

<?php
if (current_user_can('editor')){
?>

yang ni editor je boleh view, kalau bukan editor tak boleh

<?php
}
?>

Submit RSSa

 rssing.com