我试图为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 );
其他信息
之前我没有提到过这个问题,因为我认为它只会让问题变得臃肿,但目标是将它从原处移除(加入购物车之前)并将其添加回价格中,以便有效地移动它在页面上。
之前我没有包含此内容,因为我认为这将是一个简单的删除添加操作。
答案 0 :(得分:0)
add_filter( 'wc_points_rewards_single_product_message',
'remove_rewards_earn_points_message_single', 15, 2 );
function remove_rewards_earn_points_message_single( $message, $data ) {
if( is_product() )
return '';
return $message;
}
可以通过此操作将其删除,但是我不知道如何将其添加回另一个位置(