To do that you can embed an existing Shortcode inside a custom Shortcode function. The following code is an example based on other similar functional answers.
In this code I get the post id of the pages, posts or custom posts. You can specify a post ID using the shortcode id argument as in the original shortcode.
The code:
function custom_yith_render_barcode( $atts ) {
// Shortcode attributes
$atts = shortcode_atts( array(
'id' => '0', // Product ID
'hide_if_empty' => '1',
'value' => '',
'protocol' => 'EAN8',
), $atts, 'render_barcode' );
global $post;
if( '0' === $atts['id'] && $post && is_object($post) )
$id = $post->ID;
elseif( $atts['id'] > 0 )
$id = $atts['id'];
$hide = $atts['hide_if_empty'];
$value = get_post_meta( $id, $atts['value'], true ) ? get_post_meta( $id, $atts['value'], true ) : $atts['value'];
$protocol = $atts['protocol'];
return do_shortcode( "[yith_render_barcode id='$id' hide_if_empty='$hide' value='$value' protocol='$protocol']" );
}
add_shortcode('render_barcode', 'custom_yith_render_barcode');
Code goes in function.php file of your active child theme (or active theme). It should works.
USAGE -
Below the meta_key
has to be replaced with the meta key of your custom field. All other YITH Shortcode arguments are unchanged and available. Only value
argument is used to pass the custom field meta key, allowing to get the custom field value in embedded YITH shortcode.
1) In the Wordpress page or post editor:
[render_barcode value="meta_key" protocol="CODE39"]
2) In PHP code:
echo do_shortcode( "[render_barcode value='meta_key' protocol='CODE39']" );