Skip to content

Instantly share code, notes, and snippets.

@jgarciaruiz
jgarciaruiz / Added my custom column hpd
Created October 19, 2015 17:11
Add custom field column to WC products admin table
/* WC HPD */
//manage_product_posts_custom_column
add_filter( 'manage_edit-product_columns', 'products_customcol_fn' );
function products_customcol_fn($columns){
$new_columns = (is_array($columns)) ? $columns : array();
$new_columns['HPD'] = 'hpd';
return $new_columns;
}
add_action( 'manage_product_posts_custom_column', 'products_customcol_value_fn', 2 );
@jgarciaruiz
jgarciaruiz / functions.php
Last active June 18, 2022 22:45
Add custom order statuses to WooCommerce
<?php
/*
* WC - add new orders status
************************************************ */
function register_custom_order_statuses() {
register_post_status( 'wc-jv-recibido', array(
'label' => 'JV recibido',
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
@jgarciaruiz
jgarciaruiz / all-iphones-mediaqueries.css
Created April 6, 2021 15:17
All iPhone CSS media queries
/* iphone 3 */
@media only screen and (min-device-width: 320px) and (max-device-height: 480px) and (-webkit-device-pixel-ratio: 1) {
// whatever
}
/* iphone 4 */
@media only screen and (min-device-width: 320px) and (max-device-height: 480px) and (-webkit-device-pixel-ratio: 2) {
// whatever
}
@jgarciaruiz
jgarciaruiz / geolocateUser.js
Created June 27, 2019 11:01
geolocation promise
geolocateUser() {
return new Promise((resolve, reject) => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
let coordinates = {};
coordinates.lat = position.coords.latitude;
coordinates.long = position.coords.longitude
<select name="month" id="month" class="select_month">
<?php
for ($i = 1; $i <= 12; $i++){
$monthNumber = ($i < 10) ? '0'.$i : $i;
$monthStr = date('F', strtotime("$currentYear-$monthNumber"));
echo '<option value="'.$monthNumber.'"';
if ($i == $currentMonth){
echo ' selected="selected"';
}
echo '>'.$monthStr.'</option>';
@jgarciaruiz
jgarciaruiz / boldtext.php
Created March 15, 2019 11:20
php: bold text between pipes
<?php
function boldText($text){
$regxpattern = '#\|(.*?)\|#';
$html = preg_replace($regxpattern, '<strong>$1</strong>', $text);
return $html;
}
$str = 'lorem ipsum |dolor| sit amet';
echo boldText($str);
@jgarciaruiz
jgarciaruiz / boldtext.js
Created March 15, 2019 09:04
js: bold text between pipes
function boldText(text){
var regxpattern = /\|(\S(.*?\S)?)\|/gm;
var html = text.replace(regxpattern, '<strong>$1</strong>');
return html;
}
document.body.innerHTML = boldText('testing |bold| via regex');
@jgarciaruiz
jgarciaruiz / wp-ajax-upload.php
Created October 3, 2016 10:14
Enable file upload in my plugins or from the front-end [WP]
<input type="file" name="file" id="file">
<input type="submit" id="submit" name="Upload" onclick="upload();return false;">
<script type="text/javascript">
function upload(){
var formData = new FormData();
formData.append("action", "upload-attachment");
var fileInputElement = document.getElementById("file");
formData.append("async-upload", fileInputElement.files[0]);
@jgarciaruiz
jgarciaruiz / index.html
Created January 29, 2018 09:03
Treeview / Древовидная структура
<div id="collapseDVR3" class="panel-collapse collapse in">
<div class="tree ">
<ul>
<li> <span><i class="fa fa-folder-open"></i> Менюшка</span>
<ul>
<li> <span><i class="fa fa-minus-square"></i> другая Менюшка</span>
<ul>
<li> <span> ещё одна Менюшка </span> </li>
</ul>
@jgarciaruiz
jgarciaruiz / test.js
Created January 25, 2018 11:32
fetch value between hashes
// fetch value between #
var string = "Chapter #1.0# and \r\n";
var regexChapter = new RegExp(/\#(.*?)\#/g);
var regexResult = regexChapter.exec(string)
console.log( regexResult );
if( regexResult != null ){
var chapterNumber = regexResult[1];
console.log("Chapter: "+chapterNumber);