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>

email mailto: pretext

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