Skip to content

Instantly share code, notes, and snippets.

View braddalton's full-sized avatar

Brad Dalton braddalton

View GitHub Profile
@braddalton
braddalton / woocommerce-flex-slider.php
Created December 12, 2023 10:23
WooCommerce Flex Slider for Product Images https://wpsites.net/?p=114641
$options['rtl'] = true; // Example: Enable right-to-left support
$options['animation'] = 'fade'; // Example: Change animation type to fade
$options['smoothHeight'] = false; // Example: Disable smooth height transition
$options['directionNav'] = true; // Example: Enable direction navigation arrows
$options['controlNav'] = 'numbers'; // Example: Use numbers for navigation
$options['slideshow'] = true; // Example: Enable slideshow
$options['animationSpeed'] = 800; // Example: Change animation speed to 800 milliseconds
$options['animationLoop'] = true; // Example: Allow animation looping
$options['allowOneSlide'] = true; // Example: Allow carousel with only one slide
@braddalton
braddalton / default-product-type
Created December 4, 2023 17:59
Set Default Product Type to Variable in WooCommerce https://wpsites.net/?p=114472
function set_default_product_type_variable() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
// Set the default product type to "variable"
$('#product-type').val('variable').change();
});
</script>
<?php
}
@braddalton
braddalton / style.css
Created November 30, 2023 06:30
Isotope 2 Columns on Mobiles https://wpsites.net/?p=114135
@media screen and (max-width: 1024px) {
.isotope-item {
display: inline-block;
width: 48%; /* Adjust the width of each item based on the number of columns you want */
margin: 0 1% 20px; /* Adjust the margin between items and add margin below each item */
vertical-align: top; /* Align items to the top of the container */
box-sizing: border-box; /* Include padding and border in the width and height */
}
@braddalton
braddalton / functions.php
Last active November 13, 2023 15:05
Add Product Expiration Date To Order Emails Full Tutorial https://wpsites.net/product/woocommerce/add-expiration-date-to-order-emails/
add_action('woocommerce_email_order_details', 'add_custom_fields_to_order_email', 10, 4);
function add_custom_fields_to_order_email($order, $sent_to_admin, $plain_text, $email) {
foreach ($order->get_items() as $item_id => $item) {
$product_id = $item->get_product_id();
$expiration_date = get_post_meta($product_id, '_expiration_date', true);
if ( ! empty( $expiration_date ) ) {
@braddalton
braddalton / functions.php
Created November 12, 2023 13:00
Exclude products from search results in WordPress
function exclude_products_from_search($query) {
if (is_admin() || !$query->is_main_query()) {
return;
}
if ($query->is_search) {
$query->set('post_type', array('post', 'page')); // Exclude products from search results
}
}
@braddalton
braddalton / functions.php
Last active November 12, 2023 06:27
Shortcode to add custom fields to the product description https://wpsites.net/?p=114180
// Add custom field to product general settings metabox
function custom_product_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Custom field
woocommerce_wp_textarea_input(
array(
'id' => '_custom_product_description',
@braddalton
braddalton / functions.php
Last active November 10, 2023 05:19
Coupon code in WooCommerce that provides a % discount and includes a free product https://wpsites.net/?p=114158
add_action('woocommerce_before_cart', 'apply_discount_and_add_free_product');
function apply_discount_and_add_free_product() {
global $woocommerce;
if (WC()->cart->has_discount('30OFF')) {
$free_product_id = 14646;
$quantity = 1;
WC()->cart->add_to_cart($free_product_id, $quantity);
@braddalton
braddalton / style.css
Created November 9, 2023 12:02
Media Query for Filter Custom Post Type Archive Using Isotope https://wpsites.net/?p=114135
/* Media query for mobile screens */
@media only screen and (max-width: 767px) {
/* Adjust styles for filter links on mobile screens */
.isotope-filter a {
display: block; /* Make links display as block elements */
margin: 0 0 10px; /* Add margin below each link */
width: 100%; /* Make links take up full width */
}
}
register_taxonomy( 'portfolio-type', 'portfolio',
array(
'labels' => array(
'name' => _x( 'Portfolio Types', 'taxonomy general name' , 'genesis-portfolio-pro' ),
'singular_name' => _x( 'Portfolio Type' , 'taxonomy singular name', 'genesis-portfolio-pro' ),
'search_items' => __( 'Search Portfolio Types' , 'genesis-portfolio-pro' ),
'popular_items' => __( 'Popular Portfolio Types' , 'genesis-portfolio-pro' ),
'all_items' => __( 'All Types' , 'genesis-portfolio-pro' ),
'edit_item' => __( 'Edit Portfolio Type' , 'genesis-portfolio-pro' ),
'update_item' => __( 'Update Portfolio Type' , 'genesis-portfolio-pro' ),
@braddalton
braddalton / Daily Random Free Product.php
Created November 9, 2023 06:08
Daily Random Free Product for WooCommerce Changes The Price to Zero for 1 Day Only. Full Code https://wpsites.net/?p=114123
add_action('init', 'assign_random_free_product');
function assign_random_free_product() {
$today = date('Y-m-d');
$assigned_product_date = get_option('random_free_product_date');
if ( $today != $assigned_product_date ) {
$random_product_id = get_random_free_product();