Skip to content

Instantly share code, notes, and snippets.

View lawkwok's full-sized avatar

Lawrence lawkwok

View GitHub Profile
@lawkwok
lawkwok / radio-stock-status.php
Created March 10, 2017 20:56
Adds .outofstock class to WooCommerce variation input tag
add_action( 'woocommerce_after_add_to_cart_form', 'radio_waitlist_label' );
function radio_waitlist_label() {
echo "
<script>
jQuery(document).ready(function($) {
var variation_data = $('form.variations_form').attr('data-product_variations');
var variation_data = JSON.parse(variation_data);
$('.variations td.value div input').each(function() {
for (var i = 0; i < variation_data.length; i++) {
var variation = variation_data[i];
@lawkwok
lawkwok / activate-review-tab.php
Created August 3, 2016 22:37
WooCommerce - Smooth scrolls to the review tab and makes it active
<?php
add_action( 'woocommerce_after_single_product', 'activate_review_tab' );
function activate_review_tab() {
echo '<script>
jQuery(document).ready(function ($) {
$("#add_review").click(function(){
var currentTab = $(this).attr("href");
$(".woocommerce-tabs .panel").hide();
@lawkwok
lawkwok / functions.php
Created August 3, 2016 22:26
WooCoommerce - Modify [woocommerce_order_tracking] shortcode to search by custom order ID instead of the default post ID Raw
<?php
// function 'get_post_id_by_meta_key_and_value' found at https://gist.github.com/feedmeastraycat/3065969
function get_post_id_by_meta_key_and_value( $key, $value ) {
global $wpdb;
$meta = $wpdb->get_results("SELECT * FROM `".$wpdb->postmeta."` WHERE meta_key='".$wpdb->escape($key)."' AND meta_value='".$wpdb->escape($value)."'");
if (is_array( $meta ) && !empty( $meta ) && isset( $meta[0]) ) {
$meta = $meta[0];
}
if ( is_object( $meta ) ) {
return $meta->post_id;
@lawkwok
lawkwok / dropdown-stock-status.php
Last active March 9, 2019 16:30
WooCommerce - Adds stock status to the dropdown on product pages
<?php
add_action( 'woocommerce_after_add_to_cart_form', 'dropdown_waitlist_label' );
function dropdown_waitlist_label() {
echo "
<script>
jQuery(document).ready(function($) {
var variation_data = $('form.variations_form').attr('data-product_variations');
var variation_data = JSON.parse(variation_data);
@lawkwok
lawkwok / functions.php
Created May 13, 2015 23:53
Add brand name above product title in archive pages
<?php
// Gets the name of the brand
function output_brand() {
$terms = get_the_terms( $post->ID , 'brand' );
if ( empty($terms) == false ) {
foreach ( $terms as $term ) {
return $term->name;
}