Skip to content

Instantly share code, notes, and snippets.

@marcosnakamine
marcosnakamine / woocommerce.php
Last active October 25, 2020 17:21
WooCommerce - Get variable product attributes
<?php $attributes = $product->get_attributes() // GET ALL ATRIBUTES ?>
<?php foreach( $attributes as $key => $value ): ?>
<?php $attribute_name = preg_replace( '/pa_/', '', $key ) // GET ATTRIBUTE NAME ?>
<label>
<select name="attribute_pa_<?php echo $attribute_name ?>" id="attribute_pa_<?php echo $attribute_name ?>">
<option value=""><?php echo $attribute_name ?></option>
<?php $attribute_name = wc_get_product_terms( get_the_ID(), $key ) // GET ATTRIBUTE NAME ?>
<?php $attribute_slug = wc_get_product_terms( get_the_ID(), $key, array( 'fields' => 'slugs' ) ) // GET ATTRIBUTE SLUG ?>
<?php for ( $i=0; $i<count( $attribute_name ); $i++ ): // array_slice BECAUSE ARRAY INDEX IS NOT SEQUENCIAL ?>
<option value="<?php $slug = array_slice( $attribute_slug, $i, 1 ); echo $slug[0]; ?>"><?php $name = array_slice( $attribute_name, $i, 1 ); echo $name[0]; ?></option>
@rchrd2
rchrd2 / test-php-basic-auth.php
Last active March 16, 2025 12:38 — forked from westonruter/test-php-basic-auth.php
PHP basic auth example
<?php
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
@chranderson
chranderson / nvmCommands.js
Last active May 1, 2025 20:37
Useful NVM commands
// check version
node -v || node --version
// list locally installed versions of node
nvm ls
// list remove available versions of node
nvm ls-remote
// install specific version of node
@nguyenanhtu
nguyenanhtu / SSLXampp.md
Last active July 12, 2024 19:06
Guide to configure SSL in XAMPP for Windows

How to test 'https' in XAMPP for localhost ? I will guide you

Menu

  • Create certificate
  • Config Apache to access https instead of http
  • Config mod rewrite to generate SSL url
  • Config Virtual host to test site

Step 1 : Create certificate

  • Go to your XAMPP installation directory (in my case it’s E:\xampp), figure out apache folder. In this, find & run batch file
@SirDarcanos
SirDarcanos / functions.php
Last active December 8, 2023 14:17
How to Show the Product Short Description on the Shop Page
<?php
add_action( 'woocommerce_after_shop_loop_item', 'woo_show_excerpt_shop_page', 6 );
function woo_show_excerpt_shop_page() {
global $product;
echo '<p class="short-description">' . $product->post->post_excerpt . '</p>';
}
@tonykambo
tonykambo / Reduce decimal points in a float or decimal value.js
Created August 7, 2016 14:14
Redeuces to 2 decimal places. toFixed returns a string so run parseFloat again.
parseFloat(parseFloat("2039.43485").toFixed(2));
@haxpor
haxpor / scriptName.php
Last active February 6, 2018 23:01 — forked from prime31/gist:5675017
Simple PHP script showing how to send an Android push notification. Be sure to replace the API_ACCESS_KEY with a proper one from the Google API's Console page. To use the script, just execute `php scriptName.php`
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
// set only for one for safety
$registrationId = 'YOUR-REGISTRATION-ID-GOES-HERE';
// prep the bundle
$msg = array
(
@vishalbasnet23
vishalbasnet23 / functions.php
Created June 28, 2016 07:51
Create WooCommerce Subscription and activate Subscription for a user programatically.
<?php
function cpm_create_order($customer_data, $the_customer) {
global $woocommerce;
$product_id = $customer_data['sub_product'];
$variation_id = $customer_data['sub_variation'];
$user_first_name = $customer_data['first_name'];
$user_last_name = $customer_data['last_name'];
$user_email = $customer_data['user_email'];
$billing_email = $customer_data['user_email'];
$billing_state = $customer_data['cpm_state'];
@saggiyogesh
saggiyogesh / mongo_dump_restore.md
Last active December 3, 2020 18:26
Mongodb dump and restore from mlab
  • install mongodb on local machine (mongodump & mongorestore) commands are required.
  • command dumping

mongodump -h xxx11.mlab.com:11 -u user -p password --authenticationDatabase release-db -d release-db -o /home/dumps

**Options** `-h`: mlab host:port, `-u`: db user, `-p`: db user password, `--authenticationDatabase` `-d`: mlab dbname, `-o`: path to store backupfiles
  • restore command, to restore locally

    mongorestore --db dname /home/dumps

Otherwise to restore in mlab, create a new db and replace the options

@tomysmile
tomysmile / memcached_xampp.md
Created April 26, 2016 14:13
XAMPP with Memcached extension

Here are the steps that should be followed when you install memcache.

start your xampp. click on 'config' and open php.ini file. search for

;extension=php_memcache.dll

If not found add