我想meta_key
为每个 WooCommerce 产品添加一个自定义值这将是折扣率:
_discount_rate = ((_sale_price-_regular_price_)/(_regular_price)*100)
我正在尝试弄清楚如何向 WooCommerce 函数添加过滤器,woocommerce_process_product_meta
例如:
add_filter('woocommerce_process_product_meta', 'mytheme_product_save_discountrate');
function mytheme_product_save_discountrate($post_id) {
if (get_post_meta($post_id, "_sale_price")) {
$regular_price = get_post_meta($post_id, "_regular_price");
$sale_price = get_post_meta($post_id, "_sale_price");
$discount_rate = ($sale_price - $regular_price) / $regular_price * 100);
update_post_meta($post_id, '_discount_rate', $discount_rate);
}
}
我只是不确定如何检索正常价格和销售价格?