Skip to content

Instantly share code, notes, and snippets.

View gamaup's full-sized avatar

Gama Unggul Priambada gamaup

  • Inncomedia
  • Yogyakarta, ID
View GitHub Profile
@gamaup
gamaup / VeritransController.php
Created August 23, 2016 04:29
a Tiga (WP plugin) controller to handle notifications sent by veritrans
<?php
class VeritransController {
public function index() {
global $woocommerce;
// get veritrans keys depending on environment (sandbox/production)
$vt = get_option('woocommerce_veritrans_settings');
if (empty($vt)) {
return Response::json(array("success"=>false,"error"=>"veritrans setting not found"),200,array());;
}
@gamaup
gamaup / functions.php
Last active November 2, 2017 07:56
Reorder Checkout Fields
<?php
/* WooCommerce < 3.0.4 */
add_filter('woocommerce_checkout_fields','reorder_fields');
function reorder_fields($fields) {
$billing_field_order = array(
'billing_first_name',
'billing_last_name',
'billing_address_1',
'billing_email',
@gamaup
gamaup / functions.php
Last active December 9, 2019 07:47
Filter Kurir Rajaongkir pada Plugin Ongkos Kirim
<?php
add_filter('pok_rates', 'filter_couriers', 10, 2);
function filter_couriers($rates, $package) {
$filtered_rates = array();
$selected_courier = array(
'JNE - REG',
'JNE - OKE',
'JNE - YES'
);
@gamaup
gamaup / functions.php
Last active July 10, 2017 03:41
Bootstrap flash alert using Tiga Session
class Flash_Alert {
private $session;
function __construct() {
$this->session = new \Tiga\Session();
}
public function error($message) {
$this->add('danger', $message);
@gamaup
gamaup / search.sql
Last active July 25, 2017 07:33
Get nearby location based on lat-long set on postmeta.
set @latitude = xxx; — center latitude
set @longitude = xxx; — center longitude
set @distance = xx; — search distance (miles)
select p.ID, p.post_name, ((ACOS(SIN(@latitude * PI() / 180) * SIN('latitude.meta_value' * PI() / 180) + COS(@latitude * PI() / 180) * COS('latitude.meta_value' * PI() / 180) * COS((@longitude – 'longitude.meta_value') * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance
from wp_posts p
left join wp_postmeta latitude on latitude.post_id = p.ID and latitude.meta_key = '_latitude'
left join wp_postmeta longitude on longitude.post_id = p.ID and longitude.meta_key = '_longitude'
having distance < @distance;
@gamaup
gamaup / global_rule.php
Last active April 2, 2018 03:22
Custom Price Rules data structure
<?php
$rules = array(
"ruleset_f45Is7PCFWd4mjU" => array(
"label" => "Ruleset Name",
"enabled" => true,
"rules" => array(
"rule_mVk9lHtMJLw38vD" => array(
"label" => "Rule Name",
"method" => "bulk",
"rewards" => array(
<?php
add_action( 'admin_menu', 'tair_admin_menu' );
function tair_admin_menu() {
add_menu_page( 'Tes airtable', 'Tes airtable', 'manage_options', 'tair', 'tair_admin' );
}
function tair_admin() {
global $wp_version;
$records = wp_remote_get( 'https://api.airtable.com/v0/appOc1ESRgBBFWbW9/Places?view=High%20priority', array(
@gamaup
gamaup / functions.php
Created September 30, 2020 03:26
Change Checkout Address Label
<?php
// method 1.
add_filter( 'woocommerce_checkout_fields', function( $fields ) {
$fields['billing']['billing_state']['label'] = 'Provinsi';
$fields['billing']['billing_city']['label'] = 'Kabupaten';
$fields['billing']['billing_district']['label'] = 'Kecamatan';
$fields['shipping']['shipping_state']['label'] = 'Provinsi';
$fields['shipping']['shipping_city']['label'] = 'Kabupaten';
$fields['shipping']['shipping_district']['label'] = 'Kecamatan';
@gamaup
gamaup / single-action-scheduler.php
Last active September 10, 2021 07:27
Action Scheduler & Monolog Sample
<?php
// Pastikan plugin berikut telah terinstall & aktif
// Action Scheduler : https://wordpress.org/plugins/action-scheduler/
// WP Monolog : https://git.tonjoo.com/tonjoo/wp-monolog
/**
* Create job queue
*
* Param 1: Timestamp kapan job akan dirun. Isi pakai time() kalau job ingin dirun sekarang juga.
@gamaup
gamaup / functions.php
Created October 6, 2021 10:43
Passing parameters into add_action
<?php
$variable = "Some value"; // bisa array juga.
add_action( 'hook_name, function() use ($variable) {
// callback.
});