2017-05-25 5 views
0

こんにちはWooCommerce ninjas!WooCommerce管理者の了承を隠す/変更する

私はWooCommerceプラグインを開発しています。上にフォーム([変更を保存]ボタン)を送信すると、「設定が保存されました。」という更新通知が表示されます。どのように私はこの通知を隠すか変更することができます、私はwoocommerce_show_admin_noticeフィルタを使用していますが、私のプラグインクラスでは動作しません。以下は私のプラグインのコードの一部です。誰に役立つだろうフックのための任意のアイデア?

大変感謝!

<?php 
class name_of_plugin extends WC_Payment_Gateway { 
    public $error = ''; 

    // Setup our Gateway's id, description and other values 
    function __construct() { 
    $this->id = "name_of_plugin"; 
    $this->method_title = __("Name", 'domain'); 
    $this->method_description = __("Gateway Plug-in for WooCommerce", 'domain'); 
    $this->title = __("TFS VPOS", 'domain'); 
    $this->icon = null; 
    $this->has_fields = false; 
    $this->init_settings(); 
    $this->init_form_fields(); 
    $this->title = $this->get_option('title'); 


    $this->testurl = 'https://example.com/payment/api'; 
    $this->liveurl = 'https://example.com/payment/api'; 


    // Save settings 
    if (is_admin()) { 
     add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 
    } 

    // Disable Admin Notice 
    add_filter('woocommerce_show_admin_notice', array($this, 'shapeSpace_custom_admin_notice'), 10, 2); 
    // add the filter 
    add_filter('woocommerce_add_error', array($this, 'filter_woocommerce_add_notice_type'), 10, 1); 

    } // End __construct() 

    // display custom admin notice 
    public function filter_woocommerce_add_notice_type($true, $notice) { 
    // magic happen here... 
    return $true; 
    } 

答えて

1

これを削除するのに使用できる適切なフックが表示されません。

しかし、これらの2つはうまくいくようです。

私が最初に考えたのは、ページをリロードして、その時点で設定のテキストが消えるようにすることでした。このようなもの。

次に、テキストを変更したい場合は、フィルタのgettextを使用できます。

add_filter('gettext', 'woocommerce_save_settings_text', 20, 3); 
function woocommerce_save_settings_text($translated_text, $text, $domain) { 

    if (($domain == 'woocommerce') && isset($_GET['section']) && ($_GET['section'] === 'paypal')) { 
     switch ($translated_text) { 
      case 'Your settings have been saved.' : 
       $translated_text = __('Your awesome settings have been saved.', 'woocommerce'); 
       break; 
     } 
    } 
    return $translated_text; 
} 

このコードは単なる例に過ぎず、paypalの設定にも役立つことに注意してください。必要なものをすべて変更してください。

+0

@Reigelを助けてくれてありがとう、実際に私はcssを使用して非有効なセクションを隠し、次に描画エラーのための 'display_notice'メソッドを拡張しました。 – htmlbrewery

関連する問題