【问题标题】:Wordpress/Woocommerce Plugin code not showing upWordpress/Woocommerce 插件代码未显示
【发布时间】:2019-12-01 16:47:22
【问题描述】:

我想向 Woocommerce 产品页面添加一些自定义元框。当我将此代码添加到 wc-meta-boxes-functions.php 文件时,它可以工作,但是当我将它添加到我的插件文件中时,它什么也不做。我究竟做错了什么?

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>';
}

}

【问题讨论】:

  • 必须作为插件工作。你确定插件激活了吗?
  • @Kaperto 是的,很确定,因为其他功能确实有效
  • 你在运行 new WoocommerceController() 吗?
  • @Dmitry 我在哪里可以这样做,我可以在同一个文件中进行吗?

标签: php wordpress woocommerce hook-woocommerce


【解决方案1】:

所以我找到了答案: 你必须写add_action('woocommerce_product_options_general_product_data', array($this, 'woocommerce_product_custom_fields') ); 谢谢你的回答!

【讨论】:

    猜你喜欢
    • 2012-09-27
    • 2012-11-08
    • 2022-10-07
    • 1970-01-01
    • 2017-05-13
    • 2017-11-25
    • 1970-01-01
    • 2017-06-13
    • 2012-10-26
    相关资源
    最近更新 更多