Skip to content

Instantly share code, notes, and snippets.

View frankschrijvers's full-sized avatar

WPStudio frankschrijvers

View GitHub Profile
@frankschrijvers
frankschrijvers / functions.php
Last active January 30, 2024 21:24
Add descriptions to navigation items
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add description to menu items
add_filter( 'walker_nav_menu_start_el', 'wpstudio_add_description', 10, 2 );
function wpstudio_add_description( $item_output, $item ) {
$description = $item->post_content;
if (' ' !== $description ) {
return preg_replace( '/(<a.*)</', '$1' . '<span class="menu-description">' . $description . '</span><', $item_output) ;
@frankschrijvers
frankschrijvers / functions.php
Last active July 17, 2021 04:12
Add custom sidebar to WooCommerce pages
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Remove default sidebar, add shop sidebar
add_action( 'genesis_before', 'wpstudio_add_woo_sidebar', 20 );
function wpstudio_add_woo_sidebar() {
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
if( is_woocommerce() ) {
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
@frankschrijvers
frankschrijvers / functions.php
Last active July 17, 2021 04:11
Add WooCommerce mini cart to primary nav Genesis
/**
* Add WooCommerce cart to primary navigation Genesis
* @author Frank Schrijvers
* @link https://www.wpstud.io/add-woocommerce-cart-to-genesis-navigation/
*/
if ( class_exists( 'WooCommerce' ) ) {
add_action( 'genesis_header_right', 'wpstudio_add_cart' );
function wpstudio_add_cart() {
echo '<div class="mini-cart">';
echo '<a href="' . WC()->cart->get_cart_url() .'"title="View your shopping cart">'. WC()->cart->get_cart_total(). '</a>';
@frankschrijvers
frankschrijvers / functions.php
Last active July 17, 2021 04:07
Change add to cart button text
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Change add to cart button text single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wps_custom_cart_button_text' );
function wps_custom_cart_button_text() {
return __( 'Buy Product', 'your_theme_text_domain' );
@frankschrijvers
frankschrijvers / functions.php
Last active July 17, 2021 04:07
Change add to cart button text per category
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Change add to cart button text per category
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wps_custom_cart_button_text' );
function wps_custom_cart_button_text() {
global $product;
$terms = get_the_terms( $product->ID, 'product_cat' );
foreach ($terms as $term) {
@frankschrijvers
frankschrijvers / functions.php
Created September 19, 2016 08:49
Change add to cart button text per category archive pages
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Change add to cart button text per category archive pages
add_filter( 'woocommerce_product_add_to_cart_text', 'wps_archive_custom_cart_button_text' );
function wps_archive_custom_cart_button_text() {
global $product;
$terms = get_the_terms( $product->ID, 'product_cat' );
foreach ($terms as $term) {
@frankschrijvers
frankschrijvers / functions.php
Last active July 17, 2021 04:07
Set WooCommerce product button text to productname
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wps_custom_cart_button_text' );
/**
* Set product button text to productname
*/
function wps_custom_cart_button_text() {
global $product;
@frankschrijvers
frankschrijvers / functions.php
Last active July 17, 2021 04:06
Add gallery thumbs to woocommerce shop page
//* Add gallery thumbs to woocommerce shop page
add_action('woocommerce_shop_loop_item_title','wps_add_extra_product_thumbs', 5);
function wps_add_extra_product_thumbs() {
if ( is_shop() ) {
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
@frankschrijvers
frankschrijvers / functions.php
Last active March 17, 2021 05:00
Hide other shipping methods when FREE SHIPPING is available
**
* woocommerce_package_rates is a 2.1+ hook
*/
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
/**
* Hide shipping rates when free shipping is available
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
@frankschrijvers
frankschrijvers / functions.php
Created June 9, 2016 14:29
Update the order meta with the field value
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Update the order meta with field value
add_action('woocommerce_checkout_update_order_meta', 'wps_select_checkout_field_update_order_meta');
function wps_select_checkout_field_update_order_meta( $order_id ) {
if ($_POST['daypart']) update_post_meta( $order_id, 'daypart', esc_attr($_POST['daypart']));
}