Skip to content

Instantly share code, notes, and snippets.

View jameskoster's full-sized avatar
🍕

James Koster jameskoster

🍕
View GitHub Profile
@jameskoster
jameskoster / functions.php
Last active November 9, 2024 13:14
WooCommerce - Disable CSS (2.1 +)
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
@jameskoster
jameskoster / functions.php
Created March 22, 2013 20:39
Query whether WooCommerce is activated
if ( ! function_exists( 'is_woocommerce_activated' ) ) {
function is_woocommerce_activated() {
if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; }
}
}
@jameskoster
jameskoster / functions.php
Last active September 19, 2024 12:40 — forked from mikejolley/functions.php
WooCommerce - change number of upsells displayed and number of columns
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_upsells', 15 );
if ( ! function_exists( 'woocommerce_output_upsells' ) ) {
function woocommerce_output_upsells() {
woocommerce_upsell_display( 3,3 ); // Display 3 products in rows of 3
}
}
@jameskoster
jameskoster / functions.php
Last active September 19, 2024 12:40
WooCommerce - change number of products displayed per page
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 9;
return $cols;
}
@jameskoster
jameskoster / functions.php
Last active September 19, 2024 12:40
WooCommerce - set image dimensions upon theme activation
<?php
/**
* Hook in on activation
*/
/**
* Define image sizes
*/
function yourtheme_woocommerce_image_dimensions() {
global $pagenow;
@jameskoster
jameskoster / pattern.html
Created June 10, 2021 10:34
Offset gallery with fixed background & quote
<!-- wp:cover {"url":"https://jameskoster.design/wp-content/uploads/2021/06/image-from-rawpixel-id-3064488-jpeg.jpg","id":507,"hasParallax":true,"dimRatio":70,"overlayColor":"primary","contentPosition":"center center","align":"full","style":{"spacing":{"padding":{"top":"10vw","right":"10vw","bottom":"10vw","left":"10vw"}}}} -->
<div class="wp-block-cover alignfull has-background-dim-70 has-primary-background-color has-background-dim has-parallax" style="padding-top:10vw;padding-right:10vw;padding-bottom:10vw;padding-left:10vw;background-image:url(https://jameskoster.design/wp-content/uploads/2021/06/image-from-rawpixel-id-3064488-jpeg.jpg)"><div class="wp-block-cover__inner-container"><!-- wp:columns {"verticalAlignment":"top","align":"full"} -->
<div class="wp-block-columns alignfull are-vertically-aligned-top"><!-- wp:column {"verticalAlignment":"top","width":"72%","style":{"spacing":{"padding":{"right":"4vw","top":"0vw","bottom":"0vw","left":"0vw"}}}} -->
<div class="wp-block-column is-vertically-aligned-t
@jameskoster
jameskoster / functions.php
Created October 7, 2013 21:24
WooCommerce - add text after price
add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
$vat = ' (plus VAT)';
return $price . $vat;
}
@jameskoster
jameskoster / functions.php
Last active August 15, 2023 14:04
Display featured image as header background
add_action( 'wp_head', 'jk_header_background', 999 );
function jk_header_background() {
global $post;
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
if ( $post_thumbnail_id ) {
?>
@jameskoster
jameskoster / functions.php
Created March 11, 2013 11:24
WooCommerce - Add new product tab
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
@jameskoster
jameskoster / functions.php
Last active November 22, 2022 13:34
WooCommerce - Rename product data tabs
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
$tabs['description']['title'] = __( 'More Information' ); // Rename the description tab
$tabs['reviews']['title'] = __( 'Ratings' ); // Rename the reviews tab
$tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab
return $tabs;
}