在特定类别上显示并由管理员管理

时间:2019-01-29 07:03:46

标签: wordpress

我要使计算器应该显示在特定类别上。我已经为标志添加了代码,如果显示标志处于打开状态,则显示,如果没有显示则隐藏。基本上,其基于产品的皮革秀属于哪个类别。例如,汽车然后计算水果是否不应该显示。

#set port number
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetchRegistry=false
eureka.client.server.waitTimeInMsWhenSyncEmpty=0

1 个答案:

答案 0 :(得分:1)

如果要查找类别,然后中断循环并执行其余代码,则必须获得条件并根据该信息获取详细信息。

   /*
 * Display input on single product page
 * @return html
 */
function wallc_custom_option(){

    global $post;

    $terms = wp_get_post_terms( $post->ID, 'product_cat' );
    $display_flag=false;
    foreach ( $terms as $term ) 
    {       
            $wh_meta_checkbox = get_term_meta($term->term_id, 'wh_meta_checkbox', true);
            if($wh_meta_checkbox == 'on'){
                $display_flag=true;
                break;
            }

    }

    // when its display
    if($display_flag){

    // Logic of calling calculator
    $wall_width_value = isset( $_POST['wall_width_value'] ) ? sanitize_text_field( $_POST['wall_width_value'] ) : '';
    $wall_height_value = isset( $_POST['wall_height_value'] ) ? sanitize_text_field( $_POST['wall_height_value'] ) : '';
    printf( '<div class="rollcalculator">');
   ?>
   <div class="form-group"><label class="control-label" >Wall width</label>
    <input  class="form-control control-label" id="wall_width_value" name="wall_width_value"  />
    </div>

    <div class="form-group">
        <label class="control-label" >Wall height</label>
        <input  class="form-control control-label"  id="wall_height_value" name="wall_height_value" />
    </div>

    <div class="form-group"> <p><button id="estimateRole" class="btn btn-info btn-block" onclick="myFunction()">Estimate number of rolls</button></p></div>
<?php
    global $product;

    $dimensions = $product->get_dimensions();

    if ( ! empty( $dimensions ) ) {
        // all in cm
    $height= $product->get_height();
    $width=$product->get_width();
    $length=$product->get_length();

    //  CONVERT TO METER
    $pattern_height= $height/100;
    $pattern_width= $width/100;
    $pattern_repeat= $length/100;


    echo '<input type="hidden" id="pattern_height" value="'.$pattern_height.'" />';

    echo '<input type="hidden" id="pattern_width" value="'.$pattern_width.'"/>';

    echo '<input type="hidden" id="pattern_repeat" value="'.$pattern_repeat.'"/>';
    echo '<div class="form-group"><label class="control-label" >Roll Required</label><label class="form-control" id="totalRole"></label></div>';


    //correct
   // $WALL_AREA = ceil(($wall_width_value+$pattern_height) * $wall_height_value);    
?>
    <script type="text/javascript">
        function myFunction(){

          // wall input
          wall_width_value=Number($("#wall_width_value").val());
          wall_height_value=Number($("#wall_height_value").val());

          // Product dimensions

          pattern_height=Number($("#pattern_height").val());
          pattern_width=Number($("#pattern_width").val());
          pattern_repeat=Number($("#pattern_repeat").val());
          WALL_AREA = Math.ceil((wall_width_value+pattern_height) * wall_height_value);  

          wall_width_value_meter=wall_width_value/100;
         pattern_width_meter=pattern_width;

          PATTERN_AREA = (pattern_width * pattern_repeat) ;

          totalRole=Math.ceil(WALL_AREA/PATTERN_AREA);

            $("#totalRole").text(totalRole);
        }
    </script>

    <?php 


    }
}


}
add_action( 'woocommerce_after_single_product_summary', 'wallc_custom_option', 9 );