Skip to content

Instantly share code, notes, and snippets.

View braddalton's full-sized avatar

Brad Dalton braddalton

View GitHub Profile
add_filter( 'woocommerce_available_variation', 'unset_variation_attribute', 10, 3 );
function unset_variation_attribute( $data, $product, $variation ) {
// Define the attribute name you want to hide (e.g., "Size")
$attribute_to_hide = 'Size';
// Unset the attribute if it exists in the variation data
if (isset($data['attributes']['attribute_' . sanitize_title($attribute_to_hide)])) {
unset($data['attributes']['attribute_' . sanitize_title($attribute_to_hide)]);
}
@braddalton
braddalton / role.php
Created October 29, 2023 19:17
Add Checkbox To WooCommerce Checkout Page https://wpsites.net/?post_type=product&p=113989
&& in_array( 'administrator', (array) $user->roles )
@braddalton
braddalton / Custom Field for Specific Single Product.php
Last active October 25, 2023 20:29
Custom Field for Specific Single Product. More code which uses get_post_meta https://wpsites.net/product-tag/get_post_meta/
add_action( 'woocommerce_before_single_product_summary', 'hook_field' );
function hook_field() {
if ( is_product() and is_single('15412') ) {
echo get_post_meta( get_the_ID(), 'product_field', true );
}
}
@braddalton
braddalton / conditional out of stock message for specific categories.php
Last active October 22, 2023 16:25
conditional out of stock message for specific categories
$message_one = 'Message 1';
$message_two = 'Message 2';
$custom_message = has_term( 'demo', 'product_cat' ) ? $message_one : $message_two;
return $custom_message;
@braddalton
braddalton / Exclude From Specific Product Category in WooCommerce.php
Created October 21, 2023 10:41
Exclude From Specific Product Category in WooCommerce
if ( has_term( 'demo', 'product_cat' ) )
return;
@braddalton
braddalton / WC Button Next To Add To Cart Button.php
Last active October 21, 2023 06:53
Add Button Next To Add To Cart Button in WooCommerce https://wpsites.net/?p=113881
add_action( 'woocommerce_after_add_to_cart_button', 'wc_add_custom_button', 20 );
function wc_add_custom_button() {
echo '<a href="#" class="button single_add_to_cart_button">' . __('Download','woocommerce') . '</a>';
}
@braddalton
braddalton / Add Category Link on Shop Page Archives.php
Last active October 19, 2023 01:25
Add Category Link on Shop Page Archives in WooCommerce https://www.youtube.com/watch?v=sXmKLzz8U2k
@braddalton
braddalton / allow admins to view customer only content.php
Created October 13, 2023 20:12
Hide WooCommerce Product Description for Paying Customers Only https://wpsites.net/?p=113811
$result = $customer || current_user_can('administrator') ? the_content() : $not_customer;
@braddalton
braddalton / Open Product Image and Title in New Window WooCommerce.php
Created October 13, 2023 11:41
Open Product Image and Title in New Window WooCommerce
$(document).ready(function(){
$('a.woocommerce-product-gallery__trigger').click(function(){
window.open(this.href);
return false;
});
});
@braddalton
braddalton / filter_upsells_product_display.php
Created October 4, 2023 15:01
Upsells Order and Orderby
function filter_upsells_product_display( $args ) {
$args['orderby'] = 'title';
$args['order'] = 'ASC';
return $args;
}
add_filter( 'woocommerce_upsell_display_args', 'filter_upsells_product_display', 20 );