Skip to content

Instantly share code, notes, and snippets.

View cyberdev's full-sized avatar
🏠
Working from home

Nasrul Fatoni cyberdev

🏠
Working from home
View GitHub Profile
<?php
class sorter {
private $_array = array();
function __construct($array) {
$this->_array = $array;
}
public function do_sort_size(){
@cyberdev
cyberdev / utility.php
Created May 1, 2024 15:12
PHP Utility Function Trick
$arr_str = array_map('trim', explode(',', $test_str)); //explode an array separated by coma and trim them
$arr_str = array_map(fn ($img) =>$img['url'], $detail['pics']); //get deep array that have url key from pics array
@cyberdev
cyberdev / set_product_category_item.php
Last active April 28, 2024 06:04
Set Category For Product
<?php
private function set_product_category_item($category, $parent_id = null)
{
$taxonomy = 'product_cat';
if (term_exists($category, $taxonomy)) {
$category_id = get_term_by('name', $category, $taxonomy)->term_id;
} else {
//$term_data = wp_insert_term($attributes['parent2'], $taxonomy, ['parent' => $parent_id_1]);
if(!empty($parent_id)) {
@cyberdev
cyberdev / set_product_attribute.php
Last active April 28, 2024 06:01
Set Woocommerce Product Attribute
<?php
public function set_product_attribute($taxonomy, $terms, $isvariation = true)
{
$taxonomyName = $this->taxonomy_create($taxonomy);
$terms = explode('|', $terms);
$term_ids = [];
foreach ($terms as $term_name) {
$term_name = mb_substr($term_name, 0, 200);
@cyberdev
cyberdev / taxonomy_create.php
Last active April 28, 2024 06:05
Get Taxonomy or Create when not exists
<?php
public function taxonomy_create($label)
{
delete_transient('wc_attribute_taxonomies');
\WC_Cache_Helper::incr_cache_prefix('woocommerce-attributes');
// These are exported as labels, so convert the label to a name if possible first.
$attributeLabels = wp_list_pluck(wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name');
//will produce
@cyberdev
cyberdev / after_requet_test.js
Created April 28, 2024 05:09
Set collection variable after request
var jsonData = JSON.parse(responseBody);
pm.collectionVariables.set('token', jsonData.token);
@cyberdev
cyberdev / pre-request.js
Created January 26, 2024 04:02
Add variable to postman header
const this_data = JSON.parse(pm.request.body.raw)
const ref_id = this_data.ref_id
const merchant_id = pm.variables.get('merchant_id');
const secret = pm.variables.get('secret');
const sign_str = `${secret}-${merchant_id}-${ref_id}`;
const signature = CryptoJS.MD5(sign_str).toString();
pm.request.headers.add({
key: "HTTP-X-APPAPI-AUTHORIZATION",
value: signature
@cyberdev
cyberdev / periode.java
Last active January 26, 2022 18:58
iReport Periode dengan format tanggal
"PERIODE " + new SimpleDateFormat("d MMMMM yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse($P{tanggal})).toUpperCase()
@cyberdev
cyberdev / time_diff.php
Last active June 21, 2021 16:35
get time difference
<?php
function minuteDiff($str_interval, $dt_start, $dt_end, $relative = true){
if( is_string( $dt_start)) $dt_start = date_create( $dt_start);
if( is_string( $dt_end)) $dt_end = date_create( $dt_end);
$diff = date_diff( $dt_start, $dt_end, !$relative);
switch( $str_interval){
case "y":
$total = $diff->y + $diff->m / 12 + $diff->d / 365.25; break;
@cyberdev
cyberdev / getparam.js
Created May 6, 2021 08:02
Get url parameter value
function getParam(param){
return new URLSearchParams(window.location.search).get(param);
}