Php 修改主题';最小/最大数量';插件与以下代码一起工作?
我需要一些帮助以使以下各项正常工作: 我正在使用Wordpress插件Woocommerce创建一个电子商务网站,并且有许多不同的产品以网格格式出现。您可能知道,显示变体的默认方式是使用下拉菜单,这对于我瞄准的用户市场来说并不实用。相反,我从www.egggplantstudios.ca/woocommerce-product-variation-add-cart-grid/中找到了一段代码,它将变体的显示更改为网格格式,每个变体都有自己的“add to cart”按钮 这很有效 然而,我的下一个挑战是找到一种方法,为不同的变体设定最低数量限制订单。我研究并发现了WooThemes提供的一个插件“最小/最大数量”。我使用文档安装并设置了插件,在后端设置了限制,我已经准备好了 不幸的是,这个插件没有工作,无论我订购了多少,它都会显示一条错误消息。参见链接 我的第一步是联系Woothemes并询问问题的原因。他们给了我一些识别问题的步骤,并告诉我将主题改为默认的Wordpress主题。做了这件事,它成功了 我猜我从www.egggplantstudios.ca/woocommerce-product-variation-add-cart-grid/添加的代码与插件冲突…:((( 现在我对Php几乎没有经验,我不知道如何让它工作。我真的希望保持网格的原样,因为我认为这是一种更好的显示变化的方式 有人能告诉我问题的原因吗?这是一个简单的解决方法吗 我感谢任何帮助:) 谢谢 my functions.php文件中的代码:Php 修改主题';最小/最大数量';插件与以下代码一起工作?,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我需要一些帮助以使以下各项正常工作: 我正在使用Wordpress插件Woocommerce创建一个电子商务网站,并且有许多不同的产品以网格格式出现。您可能知道,显示变体的默认方式是使用下拉菜单,这对于我瞄准的用户市场来说并不实用。相反,我从www.egggplantstudios.ca/woocommerce-product-variation-add-cart-grid/中找到了一段代码,它将变体的显示更改为网格格式,每个变体都有自己的“add to cart”按钮 这很有效 然而,我的下一
function woocommerce_variable_add_to_cart(){
global $product, $post;
$variations = find_valid_variations();
// Check if the special 'price_grid' meta is set, if it is, load the default template:
if ( get_post_meta($post->ID, 'price_grid', true) ) {
// Enqueue variation scripts
wp_enqueue_script( 'wc-add-to-cart-variation' );
// Load the template
wc_get_template( 'single-product/add-to-cart/variable.php', array(
'available_variations' => $product->get_available_variations(),
'attributes' => $product->get_variation_attributes(),
'selected_attributes' => $product->get_variation_default_attributes()
) );
return;
}
// Cool, lets do our own template!
?>
<table class="variations variations-grid" cellspacing="0">
<thead>
<tr>
<th>Container Size</th>
<th>Height</th>
<th>Description</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<?php
foreach ($variations as $key => $value) {
if( !$value['variation_is_visible'] ) continue;
?>
<tr>
<?php foreach($value['attributes'] as $key => $val ) {
$val = str_replace(array('','_'), ' ', $val);
printf( '<td class="attr attr-%s">%s</td> ', $key, ucwords($val) );
}
?>
<td class="variation-description">
<?php $desc = $value['variation_description'] ?>
<?php if($desc) { ?>
<?php echo $desc ?>
<?php }?>
</td>
<td> <?php woocommerce_quantity_input(); ?></td>
<td>
<?php echo $value['price_html'];?>
</td>
<td>
<?php if( $value['is_in_stock'] ) { ?>
<form class="cart" action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" method="post" enctype='multipart/form-data'>
<?php
if(!empty($value['attributes'])){
foreach ($value['attributes'] as $attr_key => $attr_value) {
?>
<input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
<?php
}
}
?>
<button type="submit" class="single_add_to_cart_button btn btn-primary"><span class="glyphicon glyphicon-tag"></span> Add to cart</button>
<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $post->ID ); ?>" />
</form>
<?php } else { ?>
<p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
}
function find_valid_variations() {
global $product;
$variations = $product->get_available_variations();
$attributes = $product->get_attributes();
$new_variants = array();
// Loop through all variations
foreach( $variations as $variation ) {
// Peruse the attributes.
// 1. If both are explicitly set, this is a valid variation
// 2. If one is not set, that means any, and we must 'create' the rest.
$valid = true; // so far
foreach( $attributes as $slug => $args ) {
if( array_key_exists("attribute_$slug", $variation['attributes']) && !empty($variation['attributes']["attribute_$slug"]) ) {
// Exists
} else {
// Not exists, create
$valid = false; // it contains 'anys'
// loop through all options for the 'ANY' attribute, and add each
foreach( explode( '|', $attributes[$slug]['value']) as $attribute ) {
$attribute = trim( $attribute );
$new_variant = $variation;
$new_variant['attributes']["attribute_$slug"] = $attribute;
$new_variants[] = $new_variant;
}
}
}
// This contains ALL set attributes, and is itself a 'valid' variation.
if( $valid )
$new_variants[] = $variation;
}
return $new_variants;
}
函数变量添加到购物车(){
全球$product$post;
$variances=查找有效的变量();
//检查是否设置了特殊的“价格网格”元,如果设置了,则加载默认模板:
如果(获取帖子元($post->ID,'price\u grid',true)){
//将变体脚本排队
wp_排队_脚本('wc add to cart variation');
//加载模板
wc_get_模板('single product/add to cart/variable.php',数组(
“可用的\u变体”=>$product->获取可用的\u变体(),
'attributes'=>$product->get_variation_attributes(),
'选定的\u属性'=>$product->获取\u变量\u默认\u属性()
) );
返回;
}
//酷,让我们做我们自己的模板!
?>
容器大小
高度
描述
量
如果禁用最小/最大数量,变体网格是否工作?WooThemes的“最小/最大数量”是否支持对单个变体的数量限制?嗨,如果插件启用或禁用,网格工作。是插件不工作。如果我返回默认主题,它工作。是的,“最小/最大数量”支持单个变体如果这是你的主题,在这里调试将是不可能的。我将首先进入WooCommerce->System Settings->Tools并启用“模板调试模式”。然后,您可能必须系统地禁用functions.php
的部分,直到找到冲突。我没有一份混合/匹配数量的副本要自己测试,所以这可能是我能做的最好的。如果禁用最小/最大数量,您的变体网格是否工作?WooThemes的“最小/最大数量”是否支持对个体的数量限制所有变体?嗨,如果插件被启用或禁用,网格就会工作。这是一个插件,它不与网格一起工作。如果我回到默认的主题,它就会工作。是的,“最小/最大”确实支持单个变体。如果是你的主题,就不可能在这里调试。我将从WooCommerce->System Settings->Tools开始并启用“模板调试模式”。然后您可能必须系统地禁用functions.php
的部分,直到找到冲突。我没有一份混合/匹配数量的副本要自己测试,所以这可能是我能做的最好的了。