Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress “添加到购物车”按钮,并在“图像”下填写quentity字段_Wordpress_Woocommerce_Hook Woocommerce - Fatal编程技术网

Wordpress “添加到购物车”按钮,并在“图像”下填写quentity字段

Wordpress “添加到购物车”按钮,并在“图像”下填写quentity字段,wordpress,woocommerce,hook-woocommerce,Wordpress,Woocommerce,Hook Woocommerce,我想添加添加到购物车按钮,并在单个产品页面的图像下填写数量。我试过很多代码,但运气不好。一个有效但存在问题的代码是数量添加不当。我在do_action('woocommerce\u product_缩略图')之前添加以下代码my theme/woocommerce/single product/product image.php钩子 if ( ! is_shop() && ! is_product_taxonomy() ) { $quantity_field = wooc

我想添加
添加到购物车按钮,并在单个产品页面的图像下填写数量
。我试过很多代码,但运气不好。一个有效但存在问题的代码是数量添加不当。我在
do_action('woocommerce\u product_缩略图')之前添加以下代码
my theme/woocommerce/single product/product image.php
钩子

if ( ! is_shop() && ! is_product_taxonomy() ) {
    $quantity_field = woocommerce_quantity_input( array(
        'input_name'  => 'product_id',
        'input_value' => ! empty( $product->cart_item['quantity'] ) ? $product->cart_item['quantity'] : 1,
        'max_value'   => $product->backorders_allowed() ? '' : $product->get_stock_quantity(),
        'min_value'   => 0,
    ), $product, false );

    $quantity_field = str_replace( array( '<div class="quantity">', "</div>" ), '', $quantity_field );
    echo str_replace( '<input ', '<input style="max-width: 70px" ', $quantity_field );
}

echo apply_filters( 'woocommerce_loop_add_to_cart_link',
    sprintf( '<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
        esc_url( $product->add_to_cart_url() ),
        esc_attr( isset( $quantity ) ? $quantity : 1 ),
        esc_attr( $product->id ),
        esc_attr( $product->get_sku() ),
        esc_attr( isset( $class ) ? $class : 'button' ),
        esc_html( $product->add_to_cart_text() )
    ),
$product );
如果(!is_shop()&&!is_product_taxonomy()){
$quantity\u field=woocommerce\u quantity\u输入(数组(
“输入\u名称”=>“产品\u id”,
'输入值'=>!空($product->cart\U item['quantity'])?$product->cart\U item['quantity']:1,
“最大值”=>$product->backorders\U allowed()?“”:$product->get\U stock\U QUOTE(),
“最小值”=>0,
),$product,假);
$quantity\u field=str\u replace(数组(“”,“”,,$quantity\u field);

echo str_replace('Hi)在函数文件中添加此钩子

remove_action( 'woocommerce_single_product_summary','woocommerce_template_single_add_to_cart',30 );
add_action( 'woocommerce_product_thumbnails','woocommerce_template_single_add_to_cart',30 );
像默认WC一样显示

嗨,请在函数文件中添加此挂钩

remove_action( 'woocommerce_single_product_summary','woocommerce_template_single_add_to_cart',30 );
add_action( 'woocommerce_product_thumbnails','woocommerce_template_single_add_to_cart',30 );
像默认WC一样显示

你可以分享你的设计,让我们易于理解。请现在你可以看到图片请@MansukhKhandhar你可以分享你的设计,让我们易于理解。请现在你可以看到图片请@MansukhKhandhar你是一个伟大的:)@MansukhKhandhar你是一个伟大的:)@Mansukhandhar