最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How do I make a shortcode to display the shop name on Dokan?

programmeradmin0浏览0评论

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
  • Where is $store_user coming from? And Return should be lower-case return. – Jacob Peattie Commented Nov 7, 2018 at 2:12
Add a comment  | 

1 Answer 1

Reset to default 1

There 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' );)
发布评论

评论列表(0)

  1. 暂无评论