Created
November 7, 2019 16:42
-
-
Save aepnat/fa0a5b99fabf0056399ef633af8045f1 to your computer and use it in GitHub Desktop.
How to add custom shortcode for plugin woocommerce whatsapp notification
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 | |
/** | |
* Register shortcodes | |
* | |
* You should register your custom shortcode using filter wwn_shortcodes, that filter has params array and must be return as array | |
* | |
* @param array $shortcodes | |
* @return array | |
*/ | |
add_filter('wwn_shortcodes', 'wwn_register_new_shortcodes'); | |
function wwn_register_new_shortcodes($shortcodes) { | |
return array_merge($shortcodes, array( | |
'{custom_shortcode}' => 'This is a description for the custom shortcode', | |
)) | |
} | |
/** | |
* Parse Shortcode | |
* | |
* You should add filter to parse your custom shortcode. filter using patern like this: wwn_shortcode_parse_{your_custom_shortcode_without_brackets}. | |
* | |
* @param string $value | |
* @param int $order_id | |
* @param WC_Order $order | |
*/ | |
add_filter('wwn_shortcode_parse_custom_shortcode', 'wwn_parse_custom_shortcode', 15, 3); | |
function wwn_parse_custom_shortcode($value, $order_id, $order) { | |
$value = 'The shortcode will be replace by this text. Very simple right.'; | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment