Skip to content

Instantly share code, notes, and snippets.

View braddalton's full-sized avatar

Brad Dalton braddalton

View GitHub Profile
@braddalton
braddalton / Woocommerce Email Hooks.php
Created February 1, 2024 06:20
Woocommerce Email Hooks
View Woocommerce Email Hooks.php
add_action( 'woocommerce_email_header', array( $object, 'email_header' ) );
add_action( 'woocommerce_email_footer', array( $object, 'email_footer' ) );
add_action( 'woocommerce_email_order_details', array( $object, 'order_details' ), 10, 4 );
add_action( 'woocommerce_email_order_details', array( $object, 'order_schema_markup' ), 20, 4 );
add_action( 'woocommerce_email_order_meta', array( $object, 'order_meta' ), 10, 3 );
add_action( 'woocommerce_email_customer_details', array( $object, 'customer_details' ), 10, 3 );
add_action( 'woocommerce_email_customer_details', array( $object, 'email_addresses' ), 20, 3 );
add_action( 'woocommerce_email_order_details', array( $this, 'generate_order_data' ), 20, 3 );
add_action( 'woocommerce_email_order_details', array( $this, 'output_email_structured_data' ), 30, 3 );
@braddalton
braddalton / Show How Many Products Left in Stock
Last active December 19, 2023 06:35
WooCommerce Show How Many Products Left in Stock - Full Tutorial & Support https://wpsites.net/?p=114708
View Show How Many Products Left in Stock
/**
* @author Brad Dalton
* @link https://wpsites.net/?p=114708
* @copyright https://wpsites.net/disclosure-privacy/
*/
// Hook to display stock quantity on the product page
add_action( 'woocommerce_before_add_to_cart_button', 'display_stock_quantity', 10 );
// Function to display stock quantity for each product
@braddalton
braddalton / functions.php
Created December 16, 2023 17:54
Load jQuery
View functions.php
function enqueue_custom_scripts() {
wp_enqueue_script('custom-script', get_stylesheet_directory_uri() . '/js/custom-script.js', array('jquery'), '1.0', true);
}
add_action('wp_enqueue_scripts', 'enqueue_custom_scripts');
@braddalton
braddalton / custom-script.js
Last active December 16, 2023 17:54
How to add a class to submenu items when they are clicked https://wpsites.net/?p=114703
View custom-script.js
jQuery(document).ready(function($) {
// Add click event to submenu items
$('.sub-menu li').on('click', function() {
// Remove 'active' class from all submenu items
$('.sub-menu li').removeClass('active');
// Add 'active' class to the clicked submenu item
$(this).addClass('active');
});
});
@braddalton
braddalton / WC Exclude On Sale Products Shop Page.php
Last active December 14, 2023 13:04
WooCommerce Exclude On Sale Products from Shop Page https://wpsites.net/?p=114677
View WC Exclude On Sale Products Shop Page.php
add_action('pre_get_posts', 'wc_exclude_sale_items_from_shop_page');
function wc_exclude_sale_items_from_shop_page($query) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
// Check if it's the main shop page
if ( is_shop() ) {
$query->set('meta_query', array(
@braddalton
braddalton / Custom WC Settings Tab
Created December 13, 2023 13:35
Add Custom Settings Tab for Number Field to WooCommerce https://wpsites.net/?p=114654
View Custom WC Settings Tab
add_action('woocommerce_settings_tabs_exchange_rates', 'add_exchange_rate_usd_field');
add_action('woocommerce_admin_field_number', 'add_exchange_rate_usd_field');
// Add custom exchange rate field to WooCommerce settings under a new tab
function add_exchange_rate_usd_field() {
woocommerce_admin_fields(array(
array(
'type' => 'title',
'id' => 'exchange_rates_tab_title',
'title' => __('Exchange Rates', 'woocommerce'),
@braddalton
braddalton / wc-manual-order-currency-change.php
Created December 13, 2023 13:13
Change Currency for Manual Orders in WooCommerce https://wpsites.net/?p=114652
View wc-manual-order-currency-change.php
add_action('woocommerce_new_order', 'set_custom_currency_for_manual_orders', 10, 1);
function set_custom_currency_for_manual_orders($order_id) {
// Check if the order is manual (admin-created) by looking at the order status
$order = wc_get_order($order_id);
$order_status = $order->get_status();
// Specify the custom currency code you want to set for manual orders
$custom_currency_code = 'EUR';
// Check if the order is manual (e.g., status is 'on-hold' for admin-created orders)
@braddalton
braddalton / woocommerce-flex-slider.php
Created December 12, 2023 10:23
WooCommerce Flex Slider for Product Images https://wpsites.net/?p=114641
View woocommerce-flex-slider.php
$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
View default-product-type
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
View style.css
@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 */
}