Skip to content

Instantly share code, notes, and snippets.

View aliboy08's full-sized avatar

Alistair Ponce aliboy08

  • Philippines
View GitHub Profile
@aliboy08
aliboy08 / wc-create-product-variation-sample.php
Created November 13, 2023 05:43
WC - create product variation sample
<?php
pre_debug('import product variations');
$data = '[{"price":8.05,"sku":"334079-1","attributes":{"attribute_pa_qty":"","attribute_pa_colours":"","attribute_pa_print-type":""}}]';
$data = json_decode($data, true);
$product_id = 2766;
foreach( $data as $variation_data ) {
@aliboy08
aliboy08 / wc-add-product-variation-attributes-sample.php
Last active November 15, 2023 02:13
WC - add product variation attributes - sample
<?php
pre_debug('import product variation attributes');
$data = '{"_product_attributes":{"pa_qty":{"name":"pa_qty","value":"","position":2,"is_visible":1,"is_variation":1,"is_taxonomy":1},"pa_capacity":{"name":"pa_capacity","value":"","position":3,"is_visible":1,"is_variation":1,"is_taxonomy":1},"usb-speed":{"name":"USB Speed","value":"2.0 Standard | 3.0","position":4,"is_visible":0,"is_variation":1,"is_taxonomy":0},"colour":{"name":"Colour","value":"Maple | Bamboo | Walnut | Redwood","position":5,"is_visible":0,"is_variation":1,"is_taxonomy":0},"pa_print-type":{"name":"pa_print-type","value":"","position":7,"is_visible":1,"is_variation":1,"is_taxonomy":1},"printable-area":{"name":"Printable Area","value":"30mm x 12mm","position":8,"is_visible":1,"is_variation":0,"is_taxonomy":0},"material":{"name":"Material","value":"Wood | Bamboo","position":9,"is_visible":1,"is_variation":0,"is_taxonomy":0},"pa_usb-extras":{"name":"pa_usb-extras","value":"","position":11,"is_visible":1,"is_variation":1,"is_taxonomy":1},"p
@aliboy08
aliboy08 / smooth-scroll-with-elements-detection.js
Last active June 23, 2023 12:24
smooth scroll vanilla js
let current_scroll = 0;
let delta_scroll = 0;
let ease = 0.08;
let container = document.querySelector('.container');
let detect_elements = [];
function init(){
document.body.style.height = container.getBoundingClientRect().height + 'px';
@aliboy08
aliboy08 / js-canvas-image-particles-v2.js
Last active June 22, 2023 11:30
js canvas - image to particles
const canvas = document.getElementById('canvas_1');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const config = {
mouse_radius: 50,
max_distance: 200,
particle_size: 2,
image_scale: 10,
@aliboy08
aliboy08 / team-popoup
Created April 21, 2023 06:49
team popup
// html
<div class="item item-team" onclick="team_popup(this)">
<div class="e1 image"><div class="img-con"><img decoding="async" class="blazy" src="https://www.fivebyfive.com.au/wp-content/uploads/2016/01/jon@2x-640x640.webp" alt="" width="640" height="640"></div></div>
<div class="e2 name">Jon Hollenberg</div>
<div class="e3 position">Founder</div>
<div class="description hide">With over 17 years experience within the web industry, Jon is an expert in online marketing and online growth strategies. Over the last eight years he has worked with over 500 Australian and international businesses, presented seminars and delivered hundreds of online projects. Jon’s design background coupled with his strong project management skills have made him successful in merging account management and leading a creative team. Jon has a Bachelor of Multimedia from Monash University.
Jon is a keen surfer, enjoys distance running and working out in the gym.</div>
</div>
// js
@aliboy08
aliboy08 / basic-tabs
Last active April 21, 2023 04:26
basic tabs
<span class="custom_tab_nav active" onclick="custom_tab(this,'#talking_points')"><i class="icon-z-icomic"></i>Talking points</span>
<span class="custom_tab_nav" onclick="custom_tab(this, '#ideal_audiences')"><i class="icon-z-icouser"></i>Ideal Audiences</span>
<script>
var custom_tab_nav = null;
var custom_tab_content = null;
function custom_tab(e, selector){
if( custom_tab_nav ) custom_tab_nav.classList.remove('active');
custom_tab_nav = e;
custom_tab_nav.classList.add('active');
@aliboy08
aliboy08 / woo-sample-custom-shipping-options-logic.php
Last active April 12, 2023 02:01
Woocommerce sample custom shipping options logic
<?php
add_filter( 'woocommerce_package_rates', function( $rates, $package ){
$shipping_options_alias = [
'free' => 'free_shipping:24',
'bulk' => 'free_shipping:23',
'local_pickup' => 'local_pickup:25',
'express' => 'flat_rate:22',
];
@aliboy08
aliboy08 / sticky-io.js
Last active April 7, 2023 08:23
Sticky using interserctionObserver
(function(){
document.addEventListener("DOMContentLoaded", function(){
var container = document.getElementById('sticky_buttons');
var callback = function(entries, observer) {
var entry = entries[0];
if( !entry.isIntersecting ) {
entry.target.classList.add('sticky');
} else {
entry.target.classList.remove('sticky');
}
@aliboy08
aliboy08 / woo-ajax-add-to-cart.php
Created April 4, 2023 23:46
Woo Ajax Add to Cart
<?php
add_action('wp_ajax_woocommerce_ajax_add_to_cart', 'woocommerce_ajax_add_to_cart');
add_action('wp_ajax_nopriv_woocommerce_ajax_add_to_cart', 'woocommerce_ajax_add_to_cart');
function woocommerce_ajax_add_to_cart() {
$product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['product_id']));
$quantity = empty($_POST['quantity']) ? 1 : wc_stock_amount($_POST['quantity']);
$variation_id = absint($_POST['variation_id']);
$passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity);
$product_status = get_post_status($product_id);
@aliboy08
aliboy08 / woocommerce-block-checkout.js
Last active April 1, 2023 06:06
woocommerce block checkout
var upload_files_complete = false;
var form = $('form.checkout');
form.on( 'checkout_place_order', function() {
if( !upload_files_complete ) {
// uploading files...
// loading indicator
form.block({ message: null, overlayCSS: { background: '#fff', opacity: .6 } })