Skip to content

Instantly share code, notes, and snippets.

Avatar

Lawrence lawkwok

View GitHub Profile
@lawkwok
lawkwok / radio-stock-status.php
Created Mar 10, 2017
Adds .outofstock class to WooCommerce variation input tag
View radio-stock-status.php
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 Aug 3, 2016
WooCommerce - Smooth scrolls to the review tab and makes it active
View activate-review-tab.php
<?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 Aug 3, 2016
WooCoommerce - Modify [woocommerce_order_tracking] shortcode to search by custom order ID instead of the default post ID Raw
View functions.php
<?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 Mar 9, 2019
WooCommerce - Adds stock status to the dropdown on product pages
View dropdown-stock-status.php
<?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
Add brand name above product title in archive pages
View functions.php
<?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;
}