陪伴而非守候
您可以通过在实际价格后附加一些文本(例如“每公斤”)来将 WooCommerce 价格更改为按重量计算,这可以通过操作 3 个在商店/产品页面、购物车和结帐页面中显示价格的过滤器来完成;woocommerce_get_price_htmlwoocommerce_cart_item_pricewoocommerce_checkout_cart_item_quantity如果所有物品都按“每公斤”分类,您可以使用以下过滤器...... add_filter( 'woocommerce_get_price_html', 'wb_change_product_html' ); // Change and return $price_html variable using the $price and weight amount function wb_change_product_html( $price ) { $price_html = '<span class="amount">' . $price . ' per kg </span>'; // change weight measurement here return $price_html; } add_filter( 'woocommerce_cart_item_price', 'wb_change_product_price_cart' ); // Change the cart prices with $price variable and weight amount function wb_change_product_price_cart( $price ) { $price = $price . ' per kg'; // change weight measurement here return $price; } add_filter( 'woocommerce_checkout_cart_item_quantity', 'wb_checkout_review', 10, 3 ); // Change the checkput prices with $cart_item variable and weight amount function wb_checkout_review ( $quantity, $cart_item, $cart_item_key ) { $cart_item = ' <strong class="product-quantity">' . sprintf( '× %s', $cart_item['quantity'] ) . ' kg </strong>'; // change weight measurement here return $cart_item; }