Wednesday, 23 February 2022

BASIC DHTML FRONT-END USE

 <script>
        var hello = `data`;
</script>
<!-- DHTML Render -->
<div id=" apps "></div>
<!-- DHTML Start-->
<script>
document.getElementById(" apps ").innerHTML = ` ${hello} All html inside`;
</script>

Sunday, 14 November 2021

PHONE NUMBER OR EMAIL NOT REQUIRED

 // For billing email and phone - Make them not required

add_filter( 'woocommerce_billing_fields', 'filter_billing_fields', 20, 1 );
function filter_billing_fields( $billing_fields ) {
    // Only on checkout page
    if( ! is_checkout() ) return $billing_fields;

    $billing_fields['billing_phone']['required'] = false;
    $billing_fields['billing_email']['required'] = false;
    return $billing_fields;
}

Sunday, 7 November 2021

WP Snippet

 To add code to your header, use this code snippet:

/* Describe what the code snippet does so you can remember later on */
add_action('wp_head', 'your_function_name');
function your_function_name(){
?>
PASTE HEADER CODE HERE
<?php
};

To add code to your footer, use this code snippet:

/* Describe what the code snippet does so you can remember later on */
add_action('wp_footer', 'your_function_name');
function your_function_name(){
?>
PASTE FOOTER CODE HERE
<?php
};

For each snippet, make sure to change:

  • The comment description (helpful when you need to remember what a code snippet does a year later)
  • The your_function_name placeholder (both instances)
  • The PASTE X CODE HERE placeholder

Step 2: Add Code Snippets to functions.php File in Child Theme

Once you have the relevant code snippet(s) ready, you need to add them to the functions.php file of your child theme. You can either edit this file by connecting to your site via FTP. Or, you can go to Appearance → Editor and select the functions.php file. Then, paste your code at the end of the file:

Add code to functions.php file

Add code to functions.php file

Make sure to save your changes and you’re done!

If you want more control over where your header or footer code snippets show up, you can use if statements to only add the code to specific pages on your WordPress site.

For example, to only add code snippets to the header or footer of your homepage, you could use:

/* Describe what the code snippet does so you can remember later on */
add_action('wp_head', 'your_function_name');
function your_function_name(){
if(is_front_page()) {  ?>
PASTE HEADER CODE HERE
<?php  }
};

Another option is to only add the code snippets to specific posts or pages. To do that, you can use this code snippet:

/* Describe what the code snippet does so you can remember later on */
add_action('wp_head', 'your_function_name');
function your_function_name(){
if(is_single(73790)) {  ?>
PASTE HEADER CODE HERE
<?php  }
};

Make sure to replace the example number – 73790 – with the actual ID of the post or page you want to add the code snippets to.

Saturday, 1 May 2021

CHANGE WORDPRESS@ EMAIL DEFAULT TO CUSTOM

 // Change default WordPress email address

add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');
 
function new_mail_from($old) {
return 'yourname@yourdomain.com';
}
function new_mail_from_name($old) {
return 'Your Name';
}
now install this plugin Stop WP Emails Going to Spam

Tuesday, 20 April 2021

PHP: EASY ECHO PHP INSIDE HTML echo HERE

 <?php

$muhaza = "muhaza";

echo<<<HERE

<h1>$muhaza</h1>

HERE;

?>


https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

PHP RANDOM ARRAY EXTERNAL FILE. MT_RAND()

 <?php

// You can do this, programmatically, using the following code ... Test It Yourself (TIY)

$colors=(file("random.txt"));//colors array


$c1=sizeof($colors)-1;//get position of the last element within the colors array


//    -- OR, if you prefer --

//$c1=count($colors)-1;//get position of the last element within the colors array


//pick a color at random from the colors array - 'Mersenne Twister based'

$color=$colors[mt_rand(0,$c1)];


echo<<<HERE

<!DOCTYPE html>

<html>

<head>

   <meta http-equiv="refresh" content="2">

</head>

<body>

   <div style="width:400px; background-color:$color; border:1px; text-align:center;" >

     $color

   </div>

</body>

</html>

HERE;

?>

Monday, 19 April 2021

PHP : RANDOM CONTACT DISPLAY NUMBER PHONE EXTERNAL FILE


<?php
    if(isset($_POST['submit'])){
$array = (file("https://website.com/wp-content/uploads/2021/04/random.txt"));
$a = $array;
$b=array("🎟️10%","🎟️20%","🎟️30%","🎟️40%","🎟️50%");
$random_keys=array_rand($a,4);
$random_keys=array_rand($b,2);
echo $a[$random_keys[0]]."<br>";
echo "Prize:";
echo $b[$random_keys[0]]."<br>";
 $a[$random_keys[1]]."<br>";
 $a[$random_keys[2]];
    } 
?>
<center>
         <form method="post">
             <input type="submit" name="submit" value="click">
         </form>
  </center>

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

Wednesday, 24 February 2021

PHP: SWITCH WITH MULTIPLE CASE WITH SAME ANSWER

 <!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>


<body>

    <form action="switch" method="post">

        haribulan <input type="number" name="hariBulan" value="" />

        <input type="submit" value="kira">

    </form>


    <?php


    $v1 = "<b>KETUA<b>

        <br/>

        <p> Keutamaan dalam kerjaya, kerja dan kejayaan.

        Mempunyai goal dalam hidup</p>";


    error_reporting(E_ALL & ~E_NOTICE);

    switch ($_POST['hariBulan']) {

        case 1:

        case 10: {

                echo $v1;

                break;

            }

        case 2: {

                echo "Peace Maker";

                break;

            }

        case 3: {

                echo "Communicator";

                break;

            }

        case 4: {

                echo "Teacher";

                break;

            }

        case 5: {

                echo "Teacher";

                break;

            }

    }


    ?>

</body>


</html>

Thursday, 18 February 2021

JS: FUNCTION ONLOAD

  <script>
    function newContent() {
      document.open();
      document.write("<h1>Out with the old, in with the new!</h1>");
      document.close();
    }
  </script>

<div onload="newContent();">
  <p>Some original document content.</p>
</div>

Saturday, 6 February 2021

DETAIL SUMMARY Collapse HTML

<style> 

details>summary::-webkit-details-marker {

display: none; }

</style>


<details>

<summary class="p-3 mb-0 bg-primary text-white"><i class="bi bi-arrow-right-circle-fill"></i> DETAIL</summary> <p>Epcot is a theme park at Walt Disney World Resort featuring exciting attractions, international pavilions, award-winning fireworks and seasonal special events.</p>

</details>

Sunday, 29 November 2020

Iframe css full width

 <style>
iframe {
    position: fixed;
    background: #000;
    border: none;
    top: 0; right: 0;
    bottom: 0; left: 0;
    width: 100%;
    height: 100%;
}</style>

Saturday, 21 November 2020

DOUBLE LAYER IMAGE USING CSS WORK AS WATERMARK

.overlayer {
  height: 100%;
  width: 100%;
background-repeat: repeat;
  position: relative;
}

.overlayer:after {
  content: " ";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 100%;
height: 100%;
background-size:cover;
  background-image: url(https://dev.feqjaafar.com/wp-content/uploads/2020/11/Oyen-Ramaix300.png);
background-repeat: repeat;
  background-color: rgba(255, 255, 255, 0.4);
  background-blend-mode: lighten;
opacity:80%
}

PHP Wordpress Author Image

 <div class="author-image">
<?php
$get_author_id = get_the_author_meta('ID');
$get_author_gravatar = get_avatar_url($get_author_id, array('size' => 300));

if(has_post_thumbnail()){
    the_post_thumbnail();
} else {
    echo '<img src="'.$get_author_gravatar.'" alt="'.get_the_title().'" />';
}
?></div>

Tuesday, 17 November 2020

WORPDRESS AUTHOR IMAGE PHP

 <div class="author-image"><?php
$get_author_id = get_the_author_meta('ID');
$get_author_gravatar = get_avatar_url($get_author_id, array('size' => 300));
if(has_post_thumbnail()){
    the_post_thumbnail();
} else {
    echo '<img src="'.$get_author_gravatar.'" alt="'.get_the_title().'" />';
}
?></div>

Friday, 13 November 2020

MUHAZA CODE WP FUNCTION PHP

 <?php


function add_cors_http_header(){

    header("Access-Control-Allow-Origin: *");

}

add_action('init','add_cors_http_header');


/*********************************************************************************

Change expired date to 3hour

**********************************************************************************/


// function keep_me_logged_in_for_1_year( $expirein ) {

// return 3600; // 1 year in seconds

// }

// add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' );



/*********************************************************************************

Redirect member to member page

**********************************************************************************/

function my_login_redirect( $redirect_to, $request, $user ) {

    //is there a user to check?

    global $user;

    if ( isset( $user->roles ) && is_array( $user->roles ) ) {

        //check for admins

        if ( in_array( 'free member', $user->roles ) ) {

            $redirect_to = '/member';

        } 

    } 

    return $redirect_to;

}


add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );


/*********************************************************************************

Change Role to Pengedar If Purchase Package 

**********************************************************************************/

    

add_action( 'woocommerce_order_status_completed', 'change_member_to_pengedar' );

function change_member_to_pengedar( $order_id ) {

//

    $order = wc_get_order( $order_id );

    $items = $order->get_items();

    $products_to_check = array( '2559','2205','2207','2209','2211','2213','2226','2227','2230','2450','2444','2235','2237','2238','2239','2240');

    foreach ( $items as $item ) {

        if ( $order->user_id > 0 && in_array( $item['product_id'], $products_to_check )) {

            $user = new WP_User( $order->user_id );

            // Change role

            $user->remove_role( 'free member' );

$user->remove_role( 'subscriber' );

            $user->add_role( 'pengedar' );

            $user->add_role( 'customer' );

            break;

        }

    }

};

################################################################################

/*********************************************************************************

Change Role to Free Member If Purchase Product

**********************************************************************************/

    

add_action( 'woocommerce_order_status_completed', 'change_customer_to_member' );

function change_customer_to_member( $order_id ) {

//

    $order = wc_get_order( $order_id );

    $items = $order->get_items();

    $products_to_check = array('2203','2204','2206','2208','2217','2210','2212','2214','2215','2216','2228','2229','2449','2303','2232','2236','2218','2219','2220','2221','2222','2223','2224','2225','2231');

    foreach ( $items as $item ) {

        if ( $order->user_id > 0 && in_array( $item['product_id'], $products_to_check )) {

            $user = new WP_User( $order->user_id );

            // Change role

$user->remove_role( 'subscriber' );

            $user->add_role( 'free member' );

            $user->add_role( 'customer' );

            break;

        }

    }

};

################################################################################

/*********************************************************************************

Empty Cart Text Change

**********************************************************************************/

remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );

add_action( 'woocommerce_cart_is_empty', 'custom_empty_cart_message', 10 );


function custom_empty_cart_message() {

    $html  = '<div class="col-12 offset-md-1 col-md-10"><p class="cart-empty">';

    $html .= wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Cart Anda Kosong. Sila Buat Pembelian.', 'woocommerce' ) ) );

    echo $html . '</p></div>';

}


//return to shop change

add_filter( 'gettext', 'change_woocommerce_return_to_shop_text', 20, 3 );

function change_woocommerce_return_to_shop_text( $translated_text, $text, $domain ) {

       switch ( $translated_text ) {

                      case 'Return to shop' :

   $translated_text = __( 'Kembali Ke List Barang', 'woocommerce' );

   break;

  }

 return $translated_text; 


}


//redirect to #id

/*

add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );

function custom_add_to_cart_redirect() { 

    return '#pagecart'; 

break;

}*/



//masukkan data dalam column setiap kali dia login

    global $wpdb;

$pokemon = $current_user->ID;

$pengedar = 'pengedar';

$free_member = 'free member';

$hq_admin = 'admin';

if(current_user_can('administrator') ) {

$wpdb->update( 'wpmt_semak', array( 'peranan' => $hq_admin), array( 'pemilik' => $pokemon ), array( '%s' ));

}

if(current_user_can('pengedar') ) {

$wpdb->update( 'wpmt_semak', array( 'peranan' => $pengedar), array( 'pemilik' => $pokemon ), array( '%s' ));

}

if( current_user_can('subscriber') || current_user_can('free member') ) {

$wpdb->update( 'wpmt_semak', array( 'peranan' => $free_member), array( 'pemilik' => $pokemon ), array( '%s' ));

}



//masukkan data dalam column setiap kali dia login


/*

//API abang alias

function trigger_the_functions() {

  if( is_page( 26620000 ) ) {


    //start triggering

$username = $_GET['txtUsername'];

    //url.php?txtUsername=nama%20saya

echo "username is " . $username;

    $email = $_GET['txtEmail'];

    $password = $_GET['txtPassword'];

    $ConfPassword = $_GET['txtConfirmPassword'];

    

    //get_header();

    global $wpdb;

    $username = $wpdb->escape($_GET['txtUsername']);

    $email = $wpdb->escape($_GET['txtEmail']);

    $password = $wpdb->escape($_GET['txtPassword']);

    $ConfPassword = $wpdb->escape($_GET['txtConfirmPassword']);


    $error = array();

    if (strpos($username, ' ') !== FALSE) {

        $error['username_space'] = "Username has Space";

    }


    if (empty($username)) {

        $error['username_empty'] = "Username is empty";

    }


    if (username_exists($username)) {

        $error['username_exists'] = "Username already exists";

    }


    if (!is_email($email)) {

        $error['email_valid'] = "Email has no valid value";

    }


    if (email_exists($email)) {

        $error['email_existence'] = "Email already exists";

    }


    if (strcmp($password, $ConfPassword) !== 0) {

        $error['password'] = "Password didn't match";

    }


    if (count($error) == 0) {

        wp_create_user($username, $password, $email);

        echo "User Created Successfully";

        exit();

    }else{

        print_r($error);

    }

    //end abang alias

       

}

}

add_action( 'wp', 'trigger_the_functions' );

*/


################################################################################

/*********************************************************************************

Extra tab

**********************************************************************************/

/**

 * @donate     https://businessbloomer.com/bloomer-armada/

 */

  

// ------------------

// 1. Register new endpoint to use for My Account page

// Note: Resave Permalinks or it will give 404 error

  

// function muhaza_add_extra_tab_endpoint() {

//     add_rewrite_endpoint( 'extra-tab', EP_ROOT | EP_PAGES );

// }

// add_action( 'init', 'muhaza_add_extra_tab_endpoint' );

// ------------------

// 2. Add new query var

// function muhaza_extra_tab_query_vars( $vars ) {

//     $vars[] = 'extra-tab';

//     return $vars;

// } 

// add_filter( 'query_vars', 'muhaza_extra_tab_query_vars', 0 );

// ------------------

// 3. Insert the new endpoint into the My Account menu

// function muhaza_add_extra_tab_link_my_account( $items ) {

//     $items['extra-tab'] = 'Extra Tab';

//     return $items;

// }  

// add_filter( 'woocommerce_account_menu_items', 'muhaza_add_extra_tab_link_my_account' );

// ------------------

// 4. Add content to the new endpoint

// function muhaza_extra_tab_content() {

// echo '<h3>Premium WooCommerce Support</h3><p>Welcome to the WooCommerce support area. As a premium customer, you can submit a ticket should you have any WooCommerce issues with your website, snippets or customization. <i>Please contact your theme/plugin developer for theme/plugin-related support.</i></p>';

// echo do_shortcode( ' /* your shortcode here */ ' );

// }

// add_action( 'woocommerce_account_extra-tab_endpoint', 'muhaza_extra_tab_content' );

// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format



################################################################################

/*********************************************************************************

Custom Widget Dashboard Note

**********************************************************************************/

add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');

 

function my_custom_dashboard_widgets() {

global $wp_meta_boxes;

 

wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help');

}

 

function custom_dashboard_help() {

echo '<p>Welcome to Custom Blog Theme! Need help? Contact the developer <a href="mailto:yourusername@gmail.com">here</a>. For WordPress Tutorials visit: <a href="https://www.wpbeginner.com" target="_blank">WPBeginner</a></p>';

}



################################################################################

/*********************************************************************************

Enable shortcodes in text widgets

**********************************************************************************/

add_filter('widget_text','do_shortcode');


################################################################################

/*********************************************************************************

test function role 8 echo get_user_role ( $current_user->ID );

**********************************************************************************/

function get_user_role($user_id) {

global $wp_roles;


$roles = array();

$user = new WP_User( $user_id );

if ( !empty( $user->roles ) && is_array( $user->roles ) ) {

foreach ( $user->roles as $role )

$roles[] .= translate_user_role( $role );

}

return implode(', ',$roles);



################################################################################

/*********************************************************************************

display total weight

**********************************************************************************/

function bbloomer_print_cart_weight() {

   $notice = 'Your cart weight is: ' . WC()->cart->get_cart_contents_weight() . get_option( 'woocommerce_weight_unit' );

   if ( is_cart() ) {

      wc_print_notice( $notice, 'notice' );

   } else {

      wc_add_notice( $notice, 'notice' );

   }

}

add_action( 'woocommerce_before_checkout_form', 'bbloomer_print_cart_weight' );

add_action( 'woocommerce_before_cart', 'bbloomer_print_cart_weight' );



################################################################################

/*********************************************************************************

Change Direction of Continue Shopping BUtton

**********************************************************************************/

add_filter( 'woocommerce_continue_shopping_redirect', 'bbloomer_change_continue_shopping' );

 

function bbloomer_change_continue_shopping() {

   return wc_get_page_permalink( 'shop' );

}


################################################################################

/*********************************************************************************

Add "Add to Cart" buttons in Divi shop pages

**********************************************************************************/

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );


################################################################################

/*********************************************************************************

modify REST api

**********************************************************************************/

add_filter( 'rest_user_query' , 'custom_rest_user_query' );

function custom_rest_user_query( $prepared_args, $request = null ) {

  unset($prepared_args['has_published_posts']);

  return $prepared_args;

}

//modify REST api

//add role on REST api

function get_user_roles($object, $field_name, $request) {

  return get_userdata($object['id'])->roles;

}


add_action('rest_api_init', function() {

  register_rest_field('user', 'roles', array(

    'get_callback' => 'get_user_roles',

    'update_callback' => null,

    'schema' => array(

      'type' => 'array'

    )

  ));

});



/** Modify url base from wp-json to 'api'*/

//function changeRestPrefix() {

//return "persadajson"; //become persadaherbs.com/persadajson/wp/v2/

//}

//add_filter( 'rest_url_prefix', 'changeRestPrefix');



################################################################################

/*********************************************************************************

PersadaHerbs_enqueue_child_styles

**********************************************************************************/

if ( ! function_exists( 'suffice_child_enqueue_child_styles' ) ) {

function PersadaHerbs_enqueue_child_styles() {

    // loading parent style

    wp_register_style(

      'parente2-style',

      get_template_directory_uri() . '/style.css'

    );


    wp_enqueue_style( 'parente2-style' );

    // loading child style

    wp_register_style(

      'childe2-style',

      get_stylesheet_directory_uri() . '/style.css'

    );

    wp_enqueue_style( 'childe2-style');

}

}

add_action( 'wp_enqueue_scripts', 'PersadaHerbs_enqueue_child_styles' );

/*********************************************************************************

PersadaHerbs_enqueue_child_styles

**********************************************************************************/


?>

Tembus Gmail dengan TXT record

Type: TXT Name: @ / domainname.com Loadtime : 14400 Value: v=spf1 a mx ip4:SERVER_IP include:netkl.org ~all