php - 删除 Woocommerce 积分和奖励插件中的产品变化消息
问题描述
我正在尝试为 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 );
附加信息
我之前没有提到这一点,因为我认为它只会使问题变得臃肿,但目标是将其从它所在的位置(在添加到购物车之前)删除并将其重新添加到价格下方,从而有效地将其移动到页面上。
我之前没有包括这个,因为我认为这将是一个简单的删除添加操作。
解决方案
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;
}
可以通过这个删除,但我不知道如何将它添加回另一个位置(
推荐阅读
- python - 制作一个 Reddit 机器人,我得到一个 IndexError
- java - 在码头服务器中部署 webapps 健康
- oracle - Oracle物化视图的自动备份
- css - 如何放大以保持对象的中心到位?
- python-3.x - 在python中将矩阵元素转换为浮点数
- arrays - 检查 Array1 是否与 Array2 中的 Array3 匹配
- jqgrid - 使用 jqGrid Free 使用指标显示数据验证
- docker - Kubernetes-上传crisocket时出错:等待条件超时
- vsto - 功能区回调中的与号
- html - 如何限制 html 中的文本框只接受带空格的字母?