【发布时间】:2018-05-15 17:33:57
【问题描述】:
我正在尝试为 woocommerce 积分和奖励插件创建删除操作,但无法正常工作。
我之前没有尝试删除这样的操作,所以任何帮助将不胜感激:)
感谢您的阅读
我的 remove_action 是:
remove_action( 'woocommerce_before_add_to_cart_button', 'add_variation_message_to_product_summary', 25 );
他们类中的原始 add_actions:
class WC_Points_Rewards_Product {
/**
* Add product-related hooks / filters
*
* @since 1.0
*/
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_m
essage' ), 10, 2 );
add_filter( 'woocommerce_variation_sale_price_html', array( $this, 'render_variation_message' ), 10, 2 );
add_filter( 'woocommerce_available_variation', array( $this, 'render_available_variation_message' ), 10, 3 );
add_filter( 'woocommerce_show_variation_price', '__return_true' );
// delete transients
add_action( 'woocommerce_delete_product_transients', array( $this, 'delete_transients' ) );
}
以及我试图删除的功能:
/**
* Add a message about the points to the product summary
*
* @since 1.2.6
*/
public function add_variation_message_to_product_summary() {
global $product;
// make sure the product has variations (otherwise it's probably a simple product)
if ( method_exists( $product, 'get_available_variations' ) ) {
// get variations
$variations = $product->get_available_variations();
// find the variation with the most points
$points = $this->get_highest_points_variation( $variations, $product->get_id() );
$message = '';
// if we have a points value let's create a message; other wise don't print anything
if ( $points ) {
$message = $this->create_variation_message_to_product_summary( $points );
}
echo $message;
}
}
编辑 我忘了提到,如果你注释掉这个,那么我试图删除的信息实际上会被删除。
//add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'add_variation_message_to_product_summary' ), 25 );
其他信息
我之前没有提到这一点,因为我认为它只会让问题变得臃肿,但目标是将其从原来的位置移除(在添加到购物车之前)并将其重新添加到价格下方,因此有效地将其向上移动这页纸。
我之前没有包含这个,因为我认为这将是一个简单的删除添加操作。
【问题讨论】:
-
删除操作也需要类
-
@VigneshPichamani 删除操作不适用于此特定插件...但这可以通过设置来完成 :)
-
我用一些额外的细节更新了我的答案。感谢您的回复,但我需要重新添加它
-
无法像使用 woocommerce 一样删除此插件中的操作... 在 StackOverFlow 中,很多人要求此插件执行类似操作,但没有人能够找到删除的方法有效的行动......祝你好运。
标签: php wordpress woocommerce hook-woocommerce points