【发布时间】:2015-06-21 10:36:29
【问题描述】:
我有一个添加到我的产品页面的按钮,我想在 woocommerce_quantity_input() 控件中查询数量。对于我的生活,我找不到如何做到这一点。我可以获取 $product 信息和 $cart 信息,但我找不到如何获取此页面上的数量(在我将其添加到购物车之前)。
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $woocommerce;
?>
<div class="calculateshipping-button-container"
style="display:block;float:<?php echo $button_align_default; ?>;">
<div class="calculateshipping-button">
<div class="cs-btn" data-layout="button_count"
data-width="<?php echo $option_csbtn_width; ?>" data-show-faces="false">
<button type="button" class="shipping-calculator-button button"
id="showHideForm"><?php _e('Calculate Shipping', $this->app_name );?>
</button>
</div>
</div>
</div>
<?php
global $product;
global $quantity;
if(isset($_POST['calc_shipping']) && $_POST['calc_shipping'] == '1')
{
所以我想获取“添加到购物车按钮”旁边的数量
并添加到页面中:
<?php do_action( 'woocommerce_before_shipping_calculator' ); ?>
<form class="shipping_calculator" action="" method="post">
将“计算按钮”定义为
<p><button type="submit" name="calc_shipping" value="1" class="button_shipping">
<?php _e( 'Calculate', 'woocommerce' ); ?></button></p>
【问题讨论】:
-
你能详细说明你想要做什么吗?还是使用截图?我不明白你在问什么。
-
是的.. 所以我的产品页面上有一个按钮。按下时,我想查询添加到购物车旁边的 quantity_input() 中的当前计数。我不希望将其添加到计数中,我只需要在需要显示的消息中使用该值。我根据 $product 进行计算,但是我找不到页面上当前显示的数量。
-
你能显示你的代码吗? (编辑问题,因为代码在 cmets 中难以辨认)。典型的数量输入有一个类
qty用于通过 jquery 进行选择,或者名称为quantity,然后可以作为$_POST数据中的键使用。 -
更新了帖子。有什么想法吗?
标签: php forms woocommerce