dongliang_bj2016 2015-06-16 16:44
浏览 9
已采纳

产品页面上的WooCommerce查询数量

I have a button that I've added to my product page, and I want to query the quantity in the woocommerce_quantity_input() control. For the life of me I can't find how to do that. I can get $product information, and $cart information, but I can't find how to get the quantity that is on this page (before I add it to the 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')
{

so I want to get the quantity next to the "Add To Cart Button"

and is added to the page with:

<?php do_action( 'woocommerce_before_shipping_calculator' ); ?>

<form class="shipping_calculator" action="" method="post">

with the "Calculate Button" defined as

<p><button type="submit" name="calc_shipping" value="1"    class="button_shipping">
<?php _e( 'Calculate', 'woocommerce' ); ?></button></p>
  • 写回答

1条回答 默认 最新

  • duan0513 2015-06-21 02:36
    关注

    Well I had to add an ajax function to the input field that would then update a hidden field in my form. Then when the Calculate button is pressed, I have access to the updated quantity.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图