【问题标题】:WooCommerce query quantity on product pageWooCommerce 在产品页面上查询数量
【发布时间】: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


【解决方案1】:

我必须在输入字段中添加一个 ajax 函数,然后更新表单中的隐藏字段。然后当按下计算按钮时,我可以访问更新的数量。

【讨论】:

    猜你喜欢
    • 2020-01-03
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多