Php Wordpress/Woocommerce插件代码未显示
我想在Woocommerce产品页面中添加一些自定义元框。当我将此代码添加到wc-meta-box-functions.php文件时,它可以工作,但当我将其添加到插件文件时,它什么也不做。我做错了什么?Php Wordpress/Woocommerce插件代码未显示,php,wordpress,woocommerce,hook-woocommerce,Php,Wordpress,Woocommerce,Hook Woocommerce,我想在Woocommerce产品页面中添加一些自定义元框。当我将此代码添加到wc-meta-box-functions.php文件时,它可以工作,但当我将其添加到插件文件时,它什么也不做。我做错了什么? namespace Inc\Base; use Inc\Base\BaseController; /** * */ class WoocommerceController extends BaseController { function register(){ add_ac
namespace Inc\Base;
use Inc\Base\BaseController;
/**
*
*/
class WoocommerceController extends BaseController
{
function register(){
add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
// Save Fields
add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
}
// Display Fields
function woocommerce_product_custom_fields()
{
global $woocommerce, $post;
echo '<div class="product_custom_field">';
// Custom Product Text Field
woocommerce_wp_text_input(
array(
'id' => '_custom_product_text_field',
'placeholder' => 'Custom Product Text Field',
'label' => __('Custom Product Text Field', 'woocommerce'),
'desc_tip' => 'true'
)
);
//Custom Product Number Field
woocommerce_wp_text_input(
array(
'id' => '_custom_product_number_field',
'placeholder' => 'Custom Product Number Field',
'label' => __('Custom Product Number Field', 'woocommerce'),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
)
)
);
//Custom Product Textarea
woocommerce_wp_textarea_input(
array(
'id' => '_custom_product_textarea',
'placeholder' => 'Custom Product Textarea',
'label' => __('Custom Product Textarea', 'woocommerce')
)
);
echo '</div>';
}
}
namespace Inc\Base;
使用Inc\Base\BaseController;
/**
*
*/
类WoocommerceController扩展BaseController
{
函数寄存器(){
添加操作(“woocommerce\u product\u options\u general\u product\u data”、“woocommerce\u product\u custom\u fields”);
//保存字段
添加操作('woocommerce\u process\u product\u meta'、'woocommerce\u product\u custom\u fields\u save');
}
//显示字段
功能商业\产品\自定义\字段()
{
全球$woocmerce,$post;
回声';
//自定义产品文本字段
woocommerce_wp_text_输入(
排列(
'id'=>''自定义\产品\文本\字段',
'占位符'=>'自定义产品文本字段',
“标签”=>“(“自定义产品文本字段”,“woocommerce”),
“描述提示”=>“正确”
)
);
//自定义产品编号字段
woocommerce_wp_text_输入(
排列(
'id'=>''自定义\产品\编号\字段',
'占位符'=>'自定义产品编号字段',
“标签”=>“‘自定义产品编号字段’、‘woocommerce’”,
'类型'=>'编号',
“自定义_属性”=>数组(
'步骤'=>'任何',
“min”=>“0”
)
)
);
//自定义产品文本区
woocommerce\u wp\u文本区域\u输入(
排列(
'id'=>'\u自定义\u产品\u文本区域',
'占位符'=>'自定义产品文本区域',
'label'=>\('Custom Product Textarea','woocommerce')
)
);
回声';
}
}
所以我找到了答案:
您必须编写add_action('woocommerce_product_options_general_product_data',数组('woocommerce_product_custom_fields')代码>
谢谢你的回答 所以我找到了答案:
您必须编写add_action('woocommerce_product_options_general_product_data',数组('woocommerce_product_custom_fields')代码>
谢谢你的回答 这必须作为一个插件工作。你确定插件被激活了吗?@Kaperto是的,非常确定,因为其他功能可以工作。你是否运行新的WoocommerceController()?@Dmitry我在哪里可以这样做,我可以在同一个文件中这样做?这必须作为插件工作。你确定插件被激活了吗?@Kaperto是的,非常确定,因为其他函数可以工作。你是否运行新的WoocommerceController()?@Dmitry我在哪里可以这样做,我可以在同一个文件中这样做?