php - Wordpress Custom Fields -


i'm new php, confusing me little. i'm using woocommerce plugin wordpress , i'm trying add custom field display rental prices products. however, not products have rental option, want display on products give rental price.

here's code i'm using, works fine. problem displays rental price of $0 on products haven't specified rental price. instead of display $0, want not display @ all.

//add rental field add_action( 'woocommerce_product_options_pricing', 'wc_rent_product_field' ); function wc_rent_product_field() {     woocommerce_wp_text_input( array( 'id' => 'rent_price', 'class' => 'wc_input_price short', 'label' => __( 'rent', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')' ) ); }  //save rental field add_action( 'save_post', 'wc_rent_save_product' ); function wc_rent_save_product( $product_id ) {     // if auto save nothing, save when update button clicked     if ( defined( 'doing_autosave' ) && doing_autosave )         return;     if ( isset( $_post['rent_price'] ) ) {         if ( is_numeric( $_post['rent_price'] ) )             update_post_meta( $product_id, 'rent_price', $_post['rent_price'] );     } else delete_post_meta( $product_id, 'rent_price' ); }  //display rental field add_action( 'woocommerce_single_product_summary', 'wc_rent_show', 5 ); function wc_rent_show() {     global $product;     // not show on variable products     if ( $product->product_type <> 'variable' ) {         $rent = get_post_meta( $product->id, 'rent_price', true );         echo '<div class="woocommerce_msrp">';         _e( 'rent: ', 'woocommerce' );         echo '<span class="woocommerce-rent-price">' . woocommerce_price( $rent ) . '</span>';         echo '</div>';     } } 

can this? i've searched around internet looking answer, seems going on head.

  if ( $product->product_type <> 'variable' ) {     $rent = get_post_meta( $product->id, 'rent_price', true );     if($rent)>0     {     echo '<div class="woocommerce_msrp">';     _e( 'rent: ', 'woocommerce' );     echo '<span class="woocommerce-rent-price">' . woocommerce_price( $rent ) . '</span>';     echo '</div>';   } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -