I'm trying to create a shortcode to display the name of the store selling the product on the single product page. However, the shortcode doesn't show up in the single product page. I am using the Dokan Pro plugin. Here's the code I have so far, I put it in the functions.php
:
// "store name" Shortcode
add_shortcode('storename', 'shortcode_storename');
global $product, $woocommerce;
function shortcode_storename () {
return get_shop_name ( $store_user->ID, 40);
}
I'm trying to create a shortcode to display the name of the store selling the product on the single product page. However, the shortcode doesn't show up in the single product page. I am using the Dokan Pro plugin. Here's the code I have so far, I put it in the functions.php
:
// "store name" Shortcode
add_shortcode('storename', 'shortcode_storename');
global $product, $woocommerce;
function shortcode_storename () {
return get_shop_name ( $store_user->ID, 40);
}
Share
Improve this question
edited Nov 7, 2018 at 8:15
cjbj
15k16 gold badges42 silver badges89 bronze badges
asked Nov 7, 2018 at 1:47
Sean TaylorSean Taylor
1012 bronze badges
1
|
1 Answer
Reset to default 1There doesn't seem to be anything wrong with your code. First thing to check is whether it is evaluated at all by adding something like echo "WPSE!!"
in the function and see if that string turns up in the source code.
If it does turn up, the problem must be in get_shop_name
returning empty. That would be a problem with WooCommerce rather than WordPress proper.
If it does not turn up, the problem most likely is that shortcodes are not evaluated at all in the input field where you are using it. Only in the content field and the default text widget shortcodes are evaluated automatically. In other cases you must specify it like this:
add_filter ( 'input_field_name', 'do_shortcode' );)
$store_user
coming from? AndReturn
should be lower-casereturn
. – Jacob Peattie Commented Nov 7, 2018 at 2:12