移动woocommerce变化价格
我正在Woocommerce下运行我的演示商店,并且当您选择产品变体时显示的价格正好在Qty字段下方,而不是在他和最后一个变体之间。这是我functions.php文件里面试过到目前为止的代码,但它没有工作:移动woocommerce变化价格
// Move WooCommerce price
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 25);
难道我犯了一个错误的地方还是它的不正确的代码
这会变化的价格移动到下面的数量,并刚刚添加到购物车按钮。您可能需要根据需要应用一些CSS样式。
function move_variation_price() {
remove_action('woocommerce_single_variation', 'woocommerce_single_variation', 10);
add_action('woocommerce_after_add_to_cart_quantity', 'woocommerce_single_variation', 10);
}
add_action('woocommerce_before_add_to_cart_form', 'move_variation_price');
由于woocommerce_after_add_to_cart_quantity
钩在WooCommerce 3.0新增加的,为了得到上面的代码是在WooCommerce 2.6.x的工作,你将需要保存到你主题的woocommerce
文件夹覆盖single-product/add-to-cart/variation-add-to-cart-button.php
模板然后在动作钩子中添加。见下:
<?php
/**
* Single variation cart button
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.5.0
*/
if (! defined('ABSPATH')) {
exit;
}
global $product;
?>
<div class="woocommerce-variation-add-to-cart variations_button">
<?php if (! $product->is_sold_individually()) : ?>
<?php woocommerce_quantity_input(array('input_value' => isset($_POST['quantity']) ? wc_stock_amount($_POST['quantity']) : 1)); ?>
<?php endif; ?>
<?php do_action('woocommerce_after_add_to_cart_quantity'); ?>
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html($product->single_add_to_cart_text()); ?></button>
<input type="hidden" name="add-to-cart" value="<?php echo absint($product->id); ?>" />
<input type="hidden" name="product_id" value="<?php echo absint($product->id); ?>" />
<input type="hidden" name="variation_id" class="variation_id" value="0" />
</div>
这使得价格现在消失了,当我选择变化 –
对不起,'woocommerce_after_add_to_cart_quantity'只显示已被添加到WooCommerce 3.0。如果您使用的是WooCommerce 2.6.x,则需要重写'single-product/add-to-cart/variation-add-to-cart-button.php'模板以手动添加该动作钩子。 – helgatheviking
在你有2个价格的可变产品的问题。第一个在产品简短描述之前永久显示,并显示最低价格和最高价格。一旦你为这个变量产品选择了所有必要的属性值,就会显示另一个属性值(它显示了这个变化的价格)。那么你真的想把它们混合在一起吗?这不是一个方便的解决方案...考虑一下(因为当选择变体时第二个价格出现)... – LoicTheAztec