Skip to content

Instantly share code, notes, and snippets.

View braddalton's full-sized avatar

Brad Dalton braddalton

View GitHub Profile
@braddalton
braddalton / wc-product-functions.php
Last active May 24, 2024 07:47
Use woocommerce_placeholder_img_src filter hook. This is the original function containing the filter. Full Tutorial https://wpsites.net/?p=115999
function wc_placeholder_img_src( $size = 'woocommerce_thumbnail' ) {
$src = WC()->plugin_url() . '/assets/images/placeholder.png';
$placeholder_image = get_option( 'woocommerce_placeholder_image', 0 );
if ( ! empty( $placeholder_image ) ) {
if ( is_numeric( $placeholder_image ) ) {
$image = wp_get_attachment_image_src( $placeholder_image, $size );
if ( ! empty( $image[0] ) ) {
$src = $image[0];
@braddalton
braddalton / functions.php
Last active May 17, 2024 11:48
Custom loop in WooCommerce that displays specific products between specific dates. Full Code https://wpsites.net/?p=115983
function display_custom_products_before_category() {
// Define the product IDs you want to display
$custom_product_ids = array(123, 456, 789); // Replace with your product IDs
// Set the date range to display the custom products (for 1 month)
$start_date = '2024-05-01'; // Start date in 'Y-m-d' format
$end_date = '2024-06-01'; // End date in 'Y-m-d' format
$current_date = date('Y-m-d');
// Check if current date is within the range
@braddalton
braddalton / widget.php
Last active May 16, 2024 15:07
Widget Slider PHP
genesis_register_sidebar( array(
'id' => 'slider',
'name' => __( 'Slider', 'agentpress' ),
'description' => __( 'This is the slider widget area.', 'agentpress' ),
) );
add_action( 'genesis_before_content_sidebar_wrap', 'slider_before_content', 5 );
function slider_before_content() {
if ( is_front_page() )
add_action( 'genesis_after_header', 'hook_slider' );
function hook_slider() {
if ( is_front_page() ) { ?>
<div class="carousel-slider">
<div class="slide"><img src="http://placehold.it/350x150&text=Slide1"></div>
<div class="slide"><img src="http://placehold.it/350x150&text=Slide2"></div>
<div class="slide"><img src="http://placehold.it/350x150&text=Slide3"></div>
<div class="slide"><img src="http://placehold.it/350x150&text=Slide4"></div>
<div class="slide"><img src="http://placehold.it/350x150&text=Slide5"></div>
<div class="slide"><img src="http://placehold.it/350x150&text=Slide6"></div>
@braddalton
braddalton / functions.php
Last active May 17, 2024 11:50
Conditional Button Text for Out of Stock Products and Specific Attribute Full Code https://wpsites.net/?p=115979
add_filter('woocommerce_product_add_to_cart_text', 'custom_combined_add_to_cart_button_text', 10, 2);
add_filter('woocommerce_product_single_add_to_cart_text', 'custom_combined_add_to_cart_button_text', 10, 2);
function custom_combined_add_to_cart_button_text($text, $product) {
if ( ! $product->is_in_stock()) {
return __('Out of Stock', 'woocommerce');
} else {
@braddalton
braddalton / Discount per shipping method.php
Created May 15, 2024 11:50
Discount per shipping method in woocommerce
function apply_shipping_based_discounts() {
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
$chosen_shipping_method = $chosen_shipping_methods[0];
$discount = 0;
if ($chosen_shipping_method === 'free_shipping') {
$discount = 10; // Discount for free shipping
} elseif ($chosen_shipping_method === 'flat_rate') {
$discount = 5; // Discount for flat rate
} elseif ($chosen_shipping_method === 'local_pickup') {
@braddalton
braddalton / add-to-cart-shopping-cart-icon.php
Last active May 15, 2024 06:22
Replace the Add To Cart Text with a Shopping Cart Icon In WooCommerce. Download Full Code https://wpsites.net/?p=115948
// Enqueue Font Awesome
function enqueue_font_awesome() {
wp_enqueue_style( 'font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_font_awesome' );
// Change "Add to Cart" button text to a shopping cart icon
function custom_add_to_cart_text() {
echo '<i class="fas fa-shopping-cart"></i>'; // Font Awesome shopping cart icon
}
'US' => array(
'default_fee' => 100,
'over_threshold_fee' => 5,
'under_threshold_fee' => 10
),
@braddalton
braddalton / woocommerce-country-codes
Created May 8, 2024 14:12
List of Country Codes for WooCommerce PHP Coding
AX Åland Islands
AF Afghanistan
AL Albania
DZ Algeria
AD Andorra
AO Angola
AI Anguilla
AQ Antarctica
AG Antigua and Barbuda
AR Argentina
@braddalton
braddalton / wc-country-code-fees.php
Created May 8, 2024 13:41
Extra Fee Based on Billing Country At Checkout in WooCommerce https://wpsites.net/?p=115829
// Define the targeted countries and the corresponding fee
$target_countries = array(
'US' => 10, // Add $10 fee for customers from the United States
'CA' => 15, // Add $15 fee for customers from Canada
// Add more countries and fees as needed
);