Skip to content

Instantly share code, notes, and snippets.

@filipecsweb
Last active April 8, 2019 01:53
Show Gist options
  • Save filipecsweb/2c6da406b7d55acc5da1 to your computer and use it in GitHub Desktop.
Save filipecsweb/2c6da406b7d55acc5da1 to your computer and use it in GitHub Desktop.
Change WooCommerce shortcode tag name
<?php
/**
* Change WooCommerce shortcode tag name.
*
* SEE EXISTING TAGS BELOW:
*
* product
* product_page
* product_category
* product_categories
* add_to_cart
* add_to_cart_url
* products
* recent_products
* sale_products
* best_selling_products
* top_rated_products
* featured_products
* product_attribute
* related_products
* shop_messages
* woocommerce_order_tracking
* woocommerce_cart
* woocommerce_checkout
* woocommerce_my_account
*
* @link http://docs.woothemes.com/document/woocommerce-shortcodes/
* @see /wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php
*
* @param string Original shortcode tag name
*
* @return string New shortcode tag name
*/
function translate_woocommerce_shortcode_tag_name( $shortcode ) {
if ( $shortcode == 'recent_products' ) {
return 'produtos_recentes';
} else if ( $shortcode == 'sale_products' ) {
return 'produtos_em_oferta';
}
return $shortcode;
}
$tags = array(
'recent_products',
'sale_products',
);
foreach ( $tags as $tag ) {
add_filter( $tag . '_shortcode_tag', 'translate_woocommerce_shortcode_tag_name' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment