Woocommerce积分和奖励 - 删除/添加动作以移动render_product_message

时间:2017-05-02 16:27:05

标签: php wordpress function woocommerce hook-woocommerce

我试着完全按照标题所说,其中一个最新版本已经改变了:

public function __construct() {

    // add single product message immediately after product excerpt
    add_action( 'woocommerce_single_product_summary', array( $this, 'render_product_message' ) );

    // add variation message before the price is displayed
    add_action( 'woocommerce_single_product_summary', array( $this, 'add_variation_message_to_product_summary' ), 15 );

    // add the points message just before the variation price.
    add_filter( 'woocommerce_variation_price_html', array( $this, 'render_variation_message' ), 10, 2 );
    add_filter( 'woocommerce_variation_sale_price_html', array( $this, 'render_variation_message' ), 10, 2 );

    // Check for same price but variable points
    add_filter( 'woocommerce_available_variation', array( $this, 'check_for_variable_points_in_product' ) );

    // delete transients
    add_action( 'woocommerce_delete_product_transients', array( $this, 'delete_transients' ) );
}

到此:

public function __construct() {

    // add single product message immediately after product excerpt
    add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'render_product_message' ), 15 );

    // add variation message before the price is displayed
    add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'add_variation_message_to_product_summary' ), 25 );

    // add the points message just before the variation price.
    add_filter( 'woocommerce_variation_price_html', array( $this, 'render_variation_message' ), 10, 2 );
    add_filter( 'woocommerce_variation_sale_price_html', array( $this, 'render_variation_message' ), 10, 2 );

    add_filter( 'woocommerce_show_variation_price', '__return_true' );

    // delete transients
    add_action( 'woocommerce_delete_product_transients', array( $this, 'delete_transients' ) );
}

我正在尝试解决第一个add_actions的问题,首先删除然后插回到原来的位置。

令人恼火的是网上几乎没有关于此的文档,所以我已经能够阅读的内容以及插件核心/模板文件中只提到了一个我已经粘贴的内容。

我的代码不起作用,我已经将它直接添加到主题functions.php中并尝试了几个变种而没有运气。以下是我到目前为止所提出的......

1

 remove_action( 'woocommerce_before_add_to_cart_button', array( $this, 'render_product_message' ), 15 );
    remove_action( 'woocommerce_before_add_to_cart_button', array( $this, 'add_variation_message_to_product_summary' ), 25 ); 

2

remove_action( 'woocommerce_before_add_to_cart_button', 'render_product_message', 15 );
remove_action( 'woocommerce_before_add_to_cart_button', 'add_variation_message_to_product_summary', 25 );

1 个答案:

答案 0 :(得分:0)

您需要访问添加操作的类的实例才能将其删除。

文档中的示例2:https://codex.wordpress.org/Function_Reference/remove_action#Example

$this不会在课堂外工作。

您需要查看类的实例化方式,以确定是否有实用的方法来访问它。您正在寻找诸如将实例设置为全局变量或使用singleton pattern

之类的内容