5


How to add extra field into woocommerce price tab and visible to front end page these value not include in cart price. Just add the piece of code into functions file or plugin functions file and change value accordingly as in the video for more fields price only visible when you add value and save the page.



code is:
// INput feild for woocoomerce price tab

add_action( 'woocommerce_product_options_pricing', 'alsawar_add_service_to_products' );       

function alsawar_add_service_to_products() {          
woocommerce_wp_text_input( array(
'id' => 'service',
'class' => 'short wc_input_price',
'label' => __( 'Service Charges', 'woocommerce' ),
'description' => 'Service Chargs ',
'placeholder' => 'Value'
        )
    );     
}

// Saving input feild


add_action( 'save_post', 'alsawar_save_service' );

function alsawar_save_service( $product_id ) {
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
        return;
    if ( isset( $_POST['service'] ) ) {
        if ( is_numeric( $_POST['service'] ) )
            update_post_meta( $product_id, 'service', $_POST['service'] );
    } else delete_post_meta( $product_id, 'service' );
}



// Visible to front end Product page  
add_action( 'woocommerce_single_product_summary', 'alsawar_display_service', 9 );

function alsawar_display_service() {
    global $product;
    
    if ( $product->product_type <> 'variable' && $service_value = get_post_meta( $product->id, 'service', true ) ) {

        echo '<div class="woocommerce_rrp">';
        _e( 'Service Charges: ', 'woocommerce' );
        echo '<span>' . ( $service_value ) . '</span>';
        echo '</div>';
        }
   
}
// -----------------------------------------
Next
This is the most recent post.
Older Post

5 comments:

  1. Front End This Is Not Displaying

    ReplyDelete
  2. Hello I am using this plugin https://wordpress.org/plugins/woocommerce-gold-price/

    I want to display carat and Gold price on per product page so please help me how to use code.

    ReplyDelete
  3. hi, why it is notshowing in frontend,and what do for varient product

    ReplyDelete
  4. :-? :-? :-? :-? :-? :-?

    ReplyDelete

You comments awaiting for approval.

Popular Posts