Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Last active November 1, 2021 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/41c4a93503c9bb3c6c9c48a6d569f6d5 to your computer and use it in GitHub Desktop.
Save damiencarbery/41c4a93503c9bb3c6c9c48a6d569f6d5 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: WooCommerce - Free Shipping Notice
Plugin URI: http://www.damiencarbery.com
Description: Add note about free shipping for all except one product.
Author: Damien Carbery
Version: 0.1
*/
$exempt_product_id = array( 24, 1968 );
add_action( 'woocommerce_after_shop_loop_item', 'wfsn_free_shipping_notice_archive_7', 7 );
function wfsn_free_shipping_notice_archive_7() {
global $post;
global $exempt_product_id;
if (in_array( $post->ID, $exempt_product_id ) == false) {
echo '<p>woocommerce_after_shop_loop_item Priority 7; Product ID: ', $post->ID, '</p>';
}
}
add_action( 'woocommerce_after_shop_loop_item', 'wfsn_free_shipping_notice_archive_15', 15 );
function wfsn_free_shipping_notice_archive_15() {
global $post;
global $exempt_product_id;
if (in_array( $post->ID, $exempt_product_id ) == false) {
echo '<p>woocommerce_after_shop_loop_item Priority 15; Product ID: ', $post->ID, '</p>';
}
}
add_action( 'woocommerce_single_product_summary', 'wfsn_free_shipping_notice_single_25', 25 );
function wfsn_free_shipping_notice_single_25() {
global $post;
global $exempt_product_id;
if (in_array( $post->ID, $exempt_product_id ) == false) {
echo '<p><strong>woocommerce_single_product_summary Priority 25; Product ID: ', $post->ID, '</strong></p>';
}
}
add_action( 'woocommerce_single_product_summary', 'wfsn_free_shipping_notice_single_60', 60 );
function wfsn_free_shipping_notice_single_60() {
global $post;
global $exempt_product_id;
if (in_array( $post->ID, $exempt_product_id ) == false) {
echo '<p><strong>woocommerce_single_product_summary Priority 60; Product ID: ', $post->ID, '</strong></p>';
}
}
@damiencarbery
Copy link
Author

Change $exempt_product_id to an array and change the test to in_array().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment