Last active
October 15, 2018 00:09
-
-
Save EvanHerman/587859eb7ce4a6e038c3483f636878e1 to your computer and use it in GitHub Desktop.
RW Elephant Inventory Gallery - Product Data Filters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: RW Elephant Filters | |
* Plugin URI: https://www.evan-herman.com | |
* Description: Customizations for the RW Elephant Inventory Gallery plugin. | |
* Version: 1.0.0 | |
* Author: Evan Herman | |
* Author URI: https://www.evan-herman.com | |
*/ | |
/** | |
* Filter the product price, add 'each' after the price. | |
* | |
* @param string $price Product price. | |
* | |
* @return string Filtered product price. | |
*/ | |
function rw_elephant_product_rental_price( $price, $item_details ) { | |
return sprintf( '%s each', $price ); | |
} | |
add_filter( 'rw_elephant_product_rental_price', 'rw_elephant_product_rental_price', 10, 2 ); | |
/** | |
* Filter the product quantity. | |
* | |
* @param string $price Product price. | |
* | |
* @return string Filtered product price. | |
*/ | |
function rw_elephant_product_quantity( $quantity, $item_details ) { | |
if ( 0 === (int) $quantity ) { | |
return 'Out of Stock'; | |
} | |
return sprintf( '%s left', $quantity ); | |
} | |
add_filter( 'rw_elephant_product_quantity', 'rw_elephant_product_quantity', 10, 2 ); | |
/** | |
* Filter the product dimensions. | |
* | |
* @param string $dimensions Product dimensions. | |
* | |
* @return string Filtered product dimensions. | |
*/ | |
function rw_elephant_product_dimensions( $dimensions, $item_details ) { | |
switch ( $dimensions ) { | |
default: | |
return $dimensions; | |
case '20 x 30 x 45': | |
return 'Very Large'; | |
} | |
} | |
add_filter( 'rw_elephant_product_dimensions', 'rw_elephant_product_dimensions', 10, 2 ); | |
/** | |
* Output a custom tag for product 176483. | |
* | |
* @param array $tags Product tags array. | |
* | |
* @return string Filtered product tags. | |
*/ | |
function rw_elephant_product_tags( $tags, $item_details ) { | |
if ( 176483 !== (int) $item_details['inventory_item_id'] ) { | |
return $tags; | |
} | |
$tags[] = '<a href="#" class="custom-tag">Custom Tag</a>'; | |
return $tags; | |
} | |
add_filter( 'rw_elephant_product_tags', 'rw_elephant_product_tags', 10, 2 ); | |
/** | |
* Change the custom ID for product 176483. | |
* | |
* @param string $custom_id Product custom ID. | |
* | |
* @return string Filtered custom_id. | |
*/ | |
function rw_elephant_product_custom_id( $custom_id, $item_details ) { | |
if ( 176483 !== (int) $item_details['inventory_item_id'] ) { | |
return $custom_id; | |
} | |
return 'Custom ID for Product 176483'; | |
} | |
add_filter( 'rw_elephant_product_custom_id', 'rw_elephant_product_custom_id', 10, 2 ); | |
/** | |
* Change 'Custom Field 1' for product 176483. | |
* | |
* @param string $custom_field_1 Product custom ID. | |
* | |
* @return string Filtered custom_field_1. | |
*/ | |
function rw_elephant_product_custom_field_1( $custom_field, $item_details ) { | |
if ( 176483 !== (int) $item_details['inventory_item_id'] ) { | |
return $custom_field; | |
} | |
return 'Custom Field 1 for Product 176483'; | |
} | |
add_filter( 'rw_elephant_product_custom_field_1', 'rw_elephant_product_custom_field_1', 10, 2 ); | |
/** | |
* Change 'Custom Field 2' for product 176483. | |
* | |
* @param string $custom_field_2 Product custom ID. | |
* | |
* @return string Filtered custom_field_2. | |
*/ | |
function rw_elephant_product_custom_field_2( $custom_field, $item_details ) { | |
if ( 176483 !== (int) $item_details['inventory_item_id'] ) { | |
return $custom_field; | |
} | |
return 'Custom Field 2 for Product 176483'; | |
} | |
add_filter( 'rw_elephant_product_custom_field_2', 'rw_elephant_product_custom_field_2', 10, 2 ); | |
/** | |
* Remove the first item note for product 176483. | |
* | |
* @param array $item_notes Item notes array from the settings page. | |
* | |
* @return array Filtered item notes. | |
*/ | |
function rw_elephant_item_notes( $item_notes, $item_details ) { | |
if ( 176483 !== (int) $item_details['inventory_item_id'] || empty( $item_notes ) ) { | |
return $item_notes; | |
} | |
unset( $item_notes[0] ); | |
return $item_notes; | |
} | |
add_filter( 'rw_elephant_item_notes', 'rw_elephant_item_notes', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment