Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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 如何添加一个100步并在货物数量上进行记录?吴哥商业_Wordpress_Woocommerce_Hook Woocommerce - Fatal编程技术网

Wordpress 如何添加一个100步并在货物数量上进行记录?吴哥商业

Wordpress 如何添加一个100步并在货物数量上进行记录?吴哥商业,wordpress,woocommerce,hook-woocommerce,Wordpress,Woocommerce,Hook Woocommerce,我有一个网站。我编写了一个代码,将“每100g”添加到产品价格中(在图中第2点)。代码如下: add_filter( 'woocommerce_get_price_html', 'wb_change_product_html' ); function wb_change_product_html( $price ) { $cat_arr = get_the_terms(get_the_ID(),'product_cat'); //return $a[0]->name;

我有一个网站。我编写了一个代码,将“每100g”添加到产品价格中(在图中第2点)。代码如下:

add_filter( 'woocommerce_get_price_html', 'wb_change_product_html' );

function wb_change_product_html( $price ) {

    $cat_arr = get_the_terms(get_the_ID(),'product_cat');
    //return $a[0]->name;
    $temp = 0;
    foreach ($cat_arr as $singl_cat) {
        if($singl_cat->name == 'perunit') {
            $temp = 1;
        }
    }
    if ( $temp ) {
        $price_html = '<span class="amount">' . 'per unit \' ' . $price . '</span>';

    } else {
        $price_html = '<span class="amount">' . ' per 100g \ ' . $price . '</span>';
    }
    return $price_html;

}
add_filter('woocommerce_get_price_html','wb_change_product_html');
函数wb\u change\u product\u html($price){
$cat_arr=get_the_terms(get_the_ID(),'product_cat');
//返回$a[0]->名称;
$temp=0;
foreach($catu arr作为$singl_cat){
如果($singl_cat->name=='perunit'){
$temp=1;
}
}
如果($temp){
$price_html=''.'每单位\'.$price'.';
}否则{
$price_html=“‘每100克\’。$price.”;
}
返回$price_html;
}
我需要在“添加到购物车的物品数量”上添加一个铭文(在图片点1中)。 逻辑是,如果我有一个“每单位”类别,那么默认情况下一切都保持不变。但如果没有分类,则在货物数量中添加“每X克价格”字样,其中X是克的数量(最低100克),并采取100克的步骤

我不知道怎么做,有人能建议吗

这很简单(来自官方文档)-将其添加到functions.php中

/**
*调整数量输入值
*/
添加过滤器('woocommerce\u quantity\u input\u args','jk\u woocommerce\u quantity\u input\u args',10,2);//简单产品
函数jk_商业_数量_输入_参数($args,$product){
$cat_arr=get_the_terms(get_the_ID(),'product_cat');
如果('perunit'=$cat_arr[0]->名称){
if(是单数('product')){
$args['input_value']=100;//起始值(我们只想影响产品页面,而不是购物车)
}
$args['max_value']=1000;//最大值
$args['min_value']=100;//最小值
$args['step']=100;//数量步数
返回$args;
}
}
非常简单(来自官方文档)-将其添加到functions.php中

/**
*调整数量输入值
*/
添加过滤器('woocommerce\u quantity\u input\u args','jk\u woocommerce\u quantity\u input\u args',10,2);//简单产品
函数jk_商业_数量_输入_参数($args,$product){
$cat_arr=get_the_terms(get_the_ID(),'product_cat');
如果('perunit'=$cat_arr[0]->名称){
if(是单数('product')){
$args['input_value']=100;//起始值(我们只想影响产品页面,而不是购物车)
}
$args['max_value']=1000;//最大值
$args['min_value']=100;//最小值
$args['step']=100;//数量步数
返回$args;
}
}

谢谢,但我如何才能为特定的产品类别做到这一点?在这一行中,您可以看到已经应用于特定类别“perunit”的if('perunit'=$cat\u arr[0]->name){谢谢,但我如何才能为特定的产品类别做到这一点?在这一行中,您可以看到已经应用于特定类别“perunit”的
if('perunit'=$cat\u arr[0]->name){