首页 文章

用于自定义插件的Woocommerce管理工具提示

提问于
浏览
1

我构建了我的Woocommerce插件,我需要在工具提示旁边输入一些内容 . 我找到了这个函数: wc_help_tip() 来自Woocommerce Docs但是我没有't understand, and doesn'工作 .

这是我的代码:

<?php 
    $tip = "test";
    echo wc_help_tip($tip, false);
?>

当我用F12调试时,我看到了一个 Span 内容:

<span class="woocommerce-help-tip" data-tip="test"></span>

但是没有任何东西出现在前端 .

有什么想法吗?或者其他什么来放置WordPress的原生工具提示?

EDIT :我需要在不在前端的自定义管理员后端页面钩子中使用它,也不需要在woocommerce管理员后台页面中使用它

3 回答

  • 1

    这个功能是后端的佣人......

    下面是一个示例,它将在订单编辑页面中输出 tooltip

    // Displayed in Order edit pages below order details on top first column
    add_action( 'woocommerce_admin_order_data_after_order_details', 'displaying_tooltip_in_order_edit_pages', 10, 1 );
    function displaying_tooltip_in_order_edit_pages( $order ){
        ?>
            <p class="form-field form-field-wide wc-customer-custom">Some text with a tooltip <?php echo wc_help_tip("hello world"); ?></p>
        <?php
    }
    

    代码位于活动子主题(或活动主题)的function.php文件中 .

    经过测试和工作 .

    enter image description here

    因此,如果您添加一些代码以通过钩子在woocommerce管理页面中显示一些自定义字段或内容,您可以使用wc_help_tip()函数添加这些工具提示

  • 0

    您应该将您的屏幕ID添加到woocommerce . 使用woocommerce_screen_ids过滤器

    例:

    add_filter('woocommerce_screen_ids', [ $this, 'set_wc_screen_ids' ] );
    
    public function set_wc_screen_ids( $screen ){
          $screen[] = 'your_screen_id';
          return $screen;
    }
    
  • 0

    确保你已经为此安排了TipTip JS,这是可以帮助你的代码,复制下面的代码并粘贴你的所有javascript文件排队的地方

    <?php
    wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION );
    $locale = localeconv();
    $decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
    
    $params = array(
    /* translators: %s: decimal */
    'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
    /* translators: %s: price decimal separator */
    'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
    'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
    'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
    'decimal_point' => $decimal,
    'mon_decimal_point' => wc_get_price_decimal_separator(),
    'strings' => array(
    'import_products' => __( 'Import', 'woocommerce' ),
    'export_products' => __( 'Export', 'woocommerce' ),
    ),
    'urls' => array(
    'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ),
    'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
    ),
    );
    
    wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );
    wp_enqueue_script( 'woocommerce_admin' );
    

相关问题