admin管理员组文章数量:1130349
I am working on a plugin that will add messages to a WooCommerce product at set places on a single item/product page and run into an issue that to be honest I have never needed a requirement for in the past.
The issue is variable function names.
What I want to be able to do is add multiple messages at key places in a product page, while I am able to target the places I want from a custom post type via a select options box I dont know how many messages in the page someone might want to add and with only one function name this is going to cause errors such as already declared if multiple messages are added for one product.
Is there a way to generate or use 'variable_function' names in a PHP function? I have tried a few ways all have not worked and even the mighty Google has failed to help me with a work around or way to allow for this to be done.
Take the below for an example I can call this once.
add_action( 'woocommerce_before_single_product', 'variable_function', 15 );
function variable_function() {
echo 'this is the first message';
}
But what if i wanted to call the below also to add a second message at a different location I will get the error already declared on line ---,
add_action( 'woocommerce_before_add_to_cart_form', 'variable_function', 15 );
function variable_function() {
echo 'This is a second message';
}
without adding a single option for all possible areas this leaves me only able to add one message per single product and to add single options means the plugin will be bloated and not versatile.
So is there way to random generate functions name such as
add_action( 'woocommerce_before_single_product', 'variable_function'.$randomn_info, 15 );
function variable_function.$randomn_info() {
echo 'this is the first message';
}
Or am I missing something very obvious?
I appreciate any help you might be able to give!
Thanks....
I am working on a plugin that will add messages to a WooCommerce product at set places on a single item/product page and run into an issue that to be honest I have never needed a requirement for in the past.
The issue is variable function names.
What I want to be able to do is add multiple messages at key places in a product page, while I am able to target the places I want from a custom post type via a select options box I dont know how many messages in the page someone might want to add and with only one function name this is going to cause errors such as already declared if multiple messages are added for one product.
Is there a way to generate or use 'variable_function' names in a PHP function? I have tried a few ways all have not worked and even the mighty Google has failed to help me with a work around or way to allow for this to be done.
Take the below for an example I can call this once.
add_action( 'woocommerce_before_single_product', 'variable_function', 15 );
function variable_function() {
echo 'this is the first message';
}
But what if i wanted to call the below also to add a second message at a different location I will get the error already declared on line ---,
add_action( 'woocommerce_before_add_to_cart_form', 'variable_function', 15 );
function variable_function() {
echo 'This is a second message';
}
without adding a single option for all possible areas this leaves me only able to add one message per single product and to add single options means the plugin will be bloated and not versatile.
So is there way to random generate functions name such as
add_action( 'woocommerce_before_single_product', 'variable_function'.$randomn_info, 15 );
function variable_function.$randomn_info() {
echo 'this is the first message';
}
Or am I missing something very obvious?
I appreciate any help you might be able to give!
Thanks....
本文标签: woocommerce offtopicVariable function names
版权声明:本文标题:woocommerce offtopic - Variable function names 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749181332a2328659.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论