Friday, 12 March 2021

WP: add product description in WooCommerce invoice

 https://www.webtoffee.com/add-product-description-in-woocommerce-invoice/


add_filter('wf_pklist_alter_product_name','wt_pklist_alter_product_name',10,5);
function wt_pklist_alter_product_name($order_item_name, $template_type, $_product, $order_item, $order)
{
return $order_item_name.'<br />'.$_product->get_short_description();
}

Monday, 8 March 2021

Wp: If User Role This Then Echo This

 if ( current_user_can( 'manage_options' ) ) {
    echo 'Admin';
} else if ( current_user_can( 'edit_pages' ) ) {
    echo 'Editor';
} else if ( current_user_can( 'publish_posts' ) ) {
    echo 'Author';
} else if ( current_user_can( 'read' ) ) {
    echo 'Subscriber';
}
//// or Not tested
foreach ( $comment_users as $user_id ) {
    wp23234_show_user_role( $user_id );
}

function wp23234_show_user_role( $user_id ) {
    $data  = get_userdata( $user_id );
    $roles = $data->roles;

    if ( in_array( $roles, 'administrator' ) ) {
        echo 'Administrator';
    } else if ( in_array( $roles, 'editor' ) ) {
        echo 'Editor';
    } else if ( in_array( $roles, 'author' ) ) {
        echo 'Author';
    } else if ( in_array ( $roles, 'subscriber' ) ) {
        echo 'Subscriber';
    }
}
/// Or Switch
<?php
global $current_user; 
get_currentuserinfo();
switch (true)  {
 case ( user_can( $current_user, "subscriber") ):
   // Show Role
   // Show Subscriber Image
 break;
 case ( user_can( $current_user, "contributor") ):
   // Show Role
   // Show Contributor Image
 break;
 case ( user_can( $current_user, "administrator") ):
   // Show Role
   // Show Administrator Image
 break;
}
?>
///
<?php
global $current_user; 
get_currentuserinfo();
switch (true)  {
 case ( user_can( $current_user, "subscriber") ):
   echo '<img src="http:www.impho.com/images/001.jpg">';
 break;
 case ( user_can( $current_user, "contributor") ):
   echo '<img src="http:www.impho.com/images/002.jpg">';
 break;
 case ( user_can( $current_user, "administrator") ):
  echo '<img src="http:www.impho.com/images/003.jpg">';
 break;
}
?>

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' );
    }
}

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...