Wednesday, 17 June 2020

Change Woocommerce Add to Cart Text to Something Else Functions.php

// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' ); 
function woocommerce_custom_single_add_to_cart_text() {
    return __( 'Buy Now', 'woocommerce' ); 
}

// To change add to cart text on product archives(Collection) page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );  
function woocommerce_custom_product_add_to_cart_text() {
    return __( 'Buy Now', 'woocommerce' );
}

Monday, 15 June 2020

Woocommerce : Change product Role after Purchase



/////////////////////////////////Change role if purchase single product /////////////

function change_role_on_purchase( $order_id ) {

    $order = new WC_Order( $order_id );
    $items = $order->get_items();

    foreach ( $items as $item ) {
        $product_name = $item['name'];
        $product_id = $item['product_id'];
        $product_variation_id = $item['variation_id'];

        if ( $order->user_id > 0 && $product_id == '416' ) {
            update_user_meta( $order->user_id, 'paying_customer', 1 );
            $user = new WP_User( $order->user_id );

            // Remove role
            $user->remove_role( 'subscriber' ); 

            // Add role
            $user->add_role( 'premium' );
        }
    }
}

add_action( 'woocommerce_order_status_processing', 'change_role_on_purchase' );

/////////////////Change role if purchase multiple product/////////////////////

 add_action( 'woocommerce_order_status_processing', 'change_role_on_purchase' );
function change_role_on_purchase( $order_id ) {
    $order = wc_get_order( $order_id );
    $items = $order->get_items();

    $products_to_check = array( '27167', '27166' );

    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( 'friends' );
            $user->add_role( 'customer' );

            // Exit the loop
            break;
        }
    }
}

/////////////////Change role if purchase multiple product 2/////////////////////

add_action( 'woocommerce_order_status_completed', 'change_role_on_purchase' );
function change_role_on_purchase( $order_id ) {
    $order = wc_get_order( $order_id );
    $items = $order->get_items();

    $products_to_check = array( '1', '2', '3' );

    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( 'customer' );
        $user->add_role( 'new-role' );

            // Exit the loop
            break;
    }
    }
}

Tuesday, 9 June 2020

Woocommerce add to cart bottom of shop divi

"Add to Cart" buttons in Divi shop pages add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );

Saturday, 2 May 2020

Woocommerce : Reset and Uninstall Woocommerce

Delete Woocommerce Data Completely

If you need to remove ALL WooCommerce data, including products, order history, reports, etc., you need to be able to modify the site’s wp-config.php file to set a constant as true.
To do that you need to add the following code snippet to your site’s wp-config.php file.
define('WC_REMOVE_ALL_DATA', true);
Please make sure add the above snippet on its own line above the /* That’s all, stop editing! Happy blogging. */ line.
sources: https://wpglorify.com/delete-woocommerce-data/

Tuesday, 28 April 2020

Wordpress : Strict to Area e.g Putrajaya

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );

function custom_woocommerce_states( $states ) {
  $states['MY'] = array(
    'PJY' => 'Putrajaya'
  );

  return $states;
}

//add this at child theme function.php

Wednesday, 15 April 2020

AXIOS CHEAT SHEET

GET request
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

// Optionally the request above could also be done as
axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
POST request
axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
Multiple concurrent requests
function getUserAccount() {
  return axios.get('/user/12345');
}

function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}

axios.all([getUserAccount(), getUserPermissions()])
  .then(axios.spread(function (acct, perms) {
    // Both requests are now complete
  }));
POST request config
// Send a POST request
axios({
  method: 'post',
  url: '/user/12345',
  data: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
});
GET request config
// GET request for remote image
axios({
  method: 'get',
  url: 'http://bit.ly/2mTM3nY',
  responseType: 'stream'
})
  .then(function(response) {
  response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});
Create instance
var instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});

Monday, 6 April 2020

Javascript Concepts Functions Related

  • Global Scope
  • Local Scope
var greeting='Welcome to blog';
(function(){
  console.log(greeting); //Output: Welcome to blog
})();
consider above code greeting variable should be global scope, it can access inside the function,
(function(){var greeting = 'Welcome to blog';
  console.log(greeting); //Output: Welcome to blog
})();console.log(greeting); //Output:Reference-Error greeting not defined

Friday, 6 March 2020

Set Time Out Javascript setTimeout

<head>
<script>
var belon

function cocokjarum(){
    belon = setTimeout(pecah,2000);
}

function pecah() {
    alert ("dah pecah!");
}
</script>
</head>
<body>
    <button onclick="cocokjarum()">Mulakan Game</button>
</body>

Thursday, 23 January 2020

svelte router @ Svero Github

Since it's exported in CommonJS format, you should be using it with a module bundler such as Rollup or Webpack.

You can install svero via npm:

npm install --save svero

Usage

The usage is super simple:

<!-- ./App.svelte -->
<script>
  import { Router, Route } from 'svero';

  import Index from './pages/Index.svelte';
  import About from './pages/About.svelte';
  import Employees from './pages/Employees.svelte';

  let employees = [{ id: 1, name: 'Bill'}, { id:2, name: 'Sven' }];
</script>

<Router>
  <Route path="*" component={Index} />
  <Route path="/about" component={About} />
  <Route path="/about/:who/123/:where" component={About} />
  <Route path="/employees">
    <Employees {employees}/>
  </Route>
</Router>

The * wildcard simply works as a fallback. If a route fails to meet any other path, it then loads the path with the *. If there is no wildcard route and the route did not meet any other path, nothing is loaded.

Your custom props can be passed by putting your component in the Route slot (Employees example above).

Paths with parameters (:param) are passed to components via props: router.params.

Parameters like *param will capture the rest of segments. You can access them as router.params._ like other params.

A component loaded by <Route> receives a property with route details:

<!-- ./pages/About.svelte -->
<script>
  export let router = {};

  // Those contains useful information about current route status
  router.path; // /test
  router.route; // Route Object
  router.params; // /about/bill/123/kansas { who: 'bill', where: 'kansas' }
</script>

Additional properties are passed to the mounted component, e.g.

<Route component={Test} title="Some description" />

Also, you can pass an object:

<Route component={Test} props={myProps} />

Route props are omitted, but all remaining ones are passed to Test.

Routes can also render any given markup when they're active, e.g.

<Route path="/static-path">
  <h1>It works!</h1>
</Route>

You can access router within <slot /> renders by declaring let:router on <Router /> or <Route /> components (see below).

If you're building an SPA or simply want to leverage on hash-based routing for certain components try the following:

<Route path="#g/:gistId/*filePath" let:router>
  <p>Info: {JSON.stringify(router.params)}</p>
</Route>

Standard anchors and <Link /> components will work as usual:

<a href="#g/1acf21/path/to/README.md">View README.md</a>

Declaring a component <Route path="#" /> will serve as fallback when location.hash is empty.

Nesting

You can render svero components inside anything, e.g.

<Router nofallback path="/sub">
  <Route>
    <fieldset>
      <legend>Routing:</legend>
      <Router nofallback path="/sub/:bar">
        <Route let:router>{router.params.bar}!</Route>
      </Router>
      <Route path="/foo">Foo</Route>
      <Route fallback path="*" let:router>
        <summary>
          <p>Not found: {router.params._}</p>
          <details>{router.failure}</details>
        </summary>
      </Route>
      <Router nofallback path="/sub/nested">
        <Route>
          [...]
          <Route fallback path="*">not found?</Route>
          <Route path="/a">A</Route>
          <Route path="/b/:c">C</Route>
          <Route path="/:value" let:router>{JSON.stringify(router.params)}</Route>
        </Route>
      </Router>
    </fieldset>
  </Route>
</Router>

Properties determine how routing will match and render routes:

  • Use the nofallback prop for telling <Router /> to disable the fallback mechanism by default
  • Any route using the fallback prop will catch unmatched routes or potential look-up errors
  • Use the exact prop to skip this route from render just in case it does not matches
  • <Route /> without path will render only if <Router path="..." /> is active!

Note that all <Router /> paths MUST begin from the root as /sub and /sub/nested in the example.

Redirects

Sometimes you just want a route to send user to another place. You can use the redirect attribute for that.

A redirect should always be a string with a path. It uses the same pattern as path attribute. For a redirect to run, there must be a Route with the equivalent path.

<Router>
  <Route path="/company" redirect="/about-us">
  <Route path="/about-us" component={AboutUs}>
</Router>

Conditions

If you need to meet a condition in order to run a route, you can use the condition attribute. Conditions can also be used with redirect for graceful route fallback.

A condition should be either boolean or a function returning boolean. There is no support for asynchronous conditions at the moment (so keep it simple).

<Router>
  <Route path="/admin/settings" condition={isAdminLogged} redirect="/admin/login">
</Router>

Think of it as a simpler middleware. A condition will run before the route loads your component, so there is no wasteful component mounting, and no screen blinking the unwanted view.

Link Component

There is also an useful <Link> component that overrides <a> elements:

<Link href="path/here" className="btn">Hello!</Link>

The difference between <Link> and <a> is that it uses pushState whenever possible, with fallback to <a> behavior. This means that when you use <Link>, svero can update the view based on your URL trigger, without reloading the entire page.

Given href values will be normalized (on-click) if they don't start with a slash, e.g. when location.pathname === '/foo' then #bar would become /foo#bar as result.

navigateTo()

In some cases you want to navigate to routes programatically instead of letting user click on links. For this scenario we have navigateto() which takes a route as parameter and navigates imediatelly to said route.

navigateTo() receives the same treatment as <Link>: It will always try to use pushState for better performance, fallbacking to a full page redirect if it isn't supported.

Usage:

<script>
  import { onMount } from 'svelte';
  import { navigateTo } from 'svero';

  onMount(() => {
    if (localStorage.getItem('logged')) {
      navigateTo('/admin');
    }
  });
</script>

Webpack issues

If you're having trouble with Webpack failing to load svero, please replace the following rule (in Svelte rule):

exclude: /node_modules/,

with:

exclude: /node_modules\/(?!(svero)\/).*/,

More information here.

Thursday, 24 October 2019

JS : Strings

Strings


When you read lessons in this course, you can highlight a single line and save it to your notes. Simply highlight a single line with your mouse (or your finger on mobile) and then a popup will appear asking you to save it to your notes.
You will be able to find these notes in the challenge page by clicking on the Note icon on the top bar, next to the logo. Try it in the next page!
Popular notes will also be shown in yellow highlights which can be easily added to your notes with a single click. And you can also disable those popular highlights from the top right menu.

You can create a string in JavaScript by simply using the double quotes (") or single quotes (').
Here's an example:
"This is a string"; 'this is another string!'
There is no difference between using a double quote or a single quote. They are exactly the same. Both of these strings do not support interpolation (which means interpolating a variable inside of them). String interpolation will be covered in a future lesson.

Basic String properties

  • the .length property is used to return the length of the string.
Here's an example of getting the length of "Nice!":
"Nice!".length; //5
We will learn about variables later in this course, but assuming you have a variable called description, here's how you'd get its length:
description.length;

Basic String methods

Here are some common methods that you can call on strings:

.includes(searchString)

This method returns true when the searchString is included inside the parent string. For example:
"Hello World".includes("World"); // true "Hello World".includes("Potato"); // false

.toUpperCase()

This will return a new string that has all of its characters in upper case:
"hello".toUpperCase(); // "HELLO";

.toLowerCase()

This will return a new string that has all of its characters in lower case:
"NICe".toLowerCase(); // "nice";
Hint: Stuck? Feel free to use CodeToGo to search for common use cases

A note on tests & sample usage

On the left of the screen, you've got tests running your code. And in your editor, you will almost always have some sample usage code.
function sum(a, b) {
    return a + b;
}

//sample usage
sum(1, 3);
The sample usage code is meant to illustrate how your code will be used. However keep in mind that we will take the function that you wrote, and call it against several other possibilities to make sure that you've got the correct answer.
Feel free to use console.log() for the parameters of the function to see what kind of tests we're running.
So even though the sample usage is sum(1, 3), we run more tests in the background with several values. We also often run it with edge case values such as sum(0, 0). All of this simulates a real Test Driven Development environment.

A note on console.log

When solving challenges feel free to add:
console.log(variable_or_expression)
to see its result in the console on the bottom left.



You can also use it to better understand the tests that you're trying to pass.

Monday, 29 July 2019

Android Studio - Installing Android Target Package from terminal

go to: "C:\Users\YOU-USER-NAME\AppData\Local\Android\Sdk\tools\bin"
sdkmanager "platform-tools" "platforms;android-26"

Monday, 22 July 2019

NPM Install with so much ERR How to fix?

Have you face this problem?

Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:248:19)
at onErrorNT (internal/child_process.js:431:16)
at processTicksAndRejections (internal/process/task_queues.js:83:17)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
at onErrorNT (internal/child_process.js:431:16)
at processTicksAndRejections (internal/process/task_queues.js:83:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! untitled@0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the untitled@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Lini Eisha\AppData\Roaming\npm-cache_logs\2019-04-29T17_36_59_252Z-debug.log

What the solution. Well, I have settled this. By go to the user folder 1. C:/users/yourUser 2. Open in your CMD/CMDER/TERMINAL
3. Type NPM init (I use this first, but I think this can bypass)
4. Then NPM install 5. Start install NPM i react or any framework package

Friday, 19 July 2019

Saturday, 27 April 2019

Material design Card Shadow css


/* material design shadow */

  

  .mat-card-1 {
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    transition: all 0.3s cubic-bezier(.25,.8,.25,1);
    width: 95%;
    margin: 0 auto;
    display: block;
    
  }
  .mat-card-1:hover {
    box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
    width: 100%;
    margin: 0 auto;
    display: block;
  }
  
  .mat-card-2 {
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    transition: all 0.3s cubic-bezier(.25,.8,.25,1);
    width: 95%;
    margin: 0 auto;
    display: block;
  }
  .mat-card-2:hover {
    box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
    width: 100%;
    margin: 0 auto;
    display: block;
  }

  .mat-card-3 {
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    transition: all 0.3s cubic-bezier(.25,.8,.25,1);
    width: 95%;
    margin: 0 auto;
    display: block;
  }
  
  .mat-card-3:hover {
    box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
    width: 100%;
    margin: 0 auto;
    display: block;
  }
  
  .mat-card-4 {
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    transition: all 0.3s cubic-bezier(.25,.8,.25,1);
    width: 95%;
    margin: 0 auto;
    display: block;
  }
  .card-4:hover {
    box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
    width: 100%;
    margin: 0 auto;
    display: block;
  }

  .mat-hover-1 {
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    transition: all 0.3s cubic-bezier(.25,.8,.25,1);
    width: 90%;
    margin: 0 auto;
    display: block;
  }
  
  .mat-hover-1:hover {
    box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
    width: 100%;
    margin: 0 auto;
    display: block;
  }
  
  .mat-hover-2 {
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    transition: all 0.3s cubic-bezier(.25,.8,.25,1);
    width: 90%;
    margin: 0 auto;
    display: block;
  }
  .mat-hover-1:hover {
    box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
    width: 100%;
    margin: 0 auto;
    display: block;
  }

Image Hover Effect

http://imagehover.io/

Imagehover.css is a lovingly crafted CSS library allowing you to easily implement scaleable image hover effects. Choose from over 40 hover effect classes from a CSS library weighing in at a minified size of only 19KB.

https://bootsnipp.com/snippets/92e5X
card style image hover

Tembus Gmail dengan TXT record

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