Skip to content

Instantly share code, notes, and snippets.

@WPprodigy
Last active December 28, 2020 22:00
Show Gist options
  • Save WPprodigy/afd0db56bf3f67379237 to your computer and use it in GitHub Desktop.
Save WPprodigy/afd0db56bf3f67379237 to your computer and use it in GitHub Desktop.
Short snippets to edit the product data retrieved by the shortcodes.
<?php
/**
* Change the default shortcode button text for both shortcodes
*/
add_filter( 'wcepe_external_product_shortcode', 'wcepe_change_default_button_text' );
add_filter( 'wcepe_recent_external_products_shortcode', 'wcepe_change_default_button_text' );
function wcepe_change_default_button_text( $atts ) {
$atts['button'] = 'New Button Text';
return $atts;
}
/**
* Add "External Product" to the front of all product titles
*/
add_filter( 'wcepe_filter_title', 'wcepe_change_the_title' );
function wcepe_change_the_title( $title ) {
return "External Product: " . $title;
}
/**
* Make all ratings 5 stars
*/
add_filter( 'wcepe_filter_rating', 'wcepe_cheat_your_ratings' );
function wcepe_cheat_your_ratings() {
return '5';
}
/**
* Replace the price for text.
*/
add_filter( 'wcepe_filter_price', 'wcepe_hide_the_price' );
function wcepe_hide_the_price() {
return 'Call for Price';
}
/**
* Add a specific size to product images.
*/
add_filter( 'wcepe_filter_image', 'wcepe_add_image_size' );
function wcepe_add_image_size( $image ) {
// This image size must exists within WordPress
$image_size = '600x600';
// Types of images to search for
$formats = array( 'jpg', 'png', 'gif' );
foreach ( $formats as $format ) {
if ( strpos( $image, '.' . $format ) ) {
$image = str_replace( '.' . $format, '-' . $image_size . '.' . $format, $image );
}
}
return $image;
}
/**
* Add a tracking number to links
*/
add_filter( 'wcepe_filter_link', 'wcepe_add_tracking_to_links' );
function wcepe_add_tracking_to_links( $link ) {
return $link . "?tracking-number=123";
}
/**
* Add product specific tracking links.
*/
add_filter( 'wcepe_filter_link', 'wcepe_add_tracking_to_links_per_product' );
function wcepe_add_tracking_to_links_per_product( $link ) {
switch ($link) {
case 'http://mysite.com/product/product-1/':
$link = 'http://mysite.com/product/product-1/?tracking-number=123';
break;
case 'http://mysite.com/product/product-2/':
$link = 'http://mysite.com/product/product-2/?tracking-number=456';
break;
case 'http://mysite.com/product/product-3/':
$link = 'http://mysite.com/product/product-3/?tracking-number=789';
break;
}
return $link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment