• Hi, I want to output all the information I stored to my rate table wp database…
    how can I do that using this code…??
    Or am I doing it right?Thanks

    // add the settings under ‘General’ sub-menu
    add_action( ‘woocommerce_product_options_general_product_data’, ‘ayg_add_custom_settings’ );
    function ayg_add_custom_settings() {
    global $woocommerce, $post;
    echo ‘<div class=”options_group”>’;
    // Create dropdown for via
    woocommerce_wp_select(
    array(
    ‘id’ => ‘ayg_via’,
    ‘label’ => __( ‘Via’, ‘woocommerce’ ),
    ‘required’ => false,
    ‘clear’ => false,
    ‘type’ => ‘select’,
    ‘options’ => array(
    ‘option_a’ => __(‘cebu’, ‘woocommerce’ ),
    ‘option_b’ => __(‘clark’, ‘woocommerce’ ),
    ‘option_c’ => __(‘davao’, ‘woocommerce’ ),
    ‘option_d’ => __(‘Iloilo’, ‘woocommerce’ ),
    ‘option_d’ => __(‘Manila’, ‘woocommerce’ )
    )));

    echo ‘</div>’;
    // Create location
    woocommerce_wp_text_input(
    array(
    ‘id’ => ‘ayg_location’,
    ‘label’ => __(‘location’, ‘woocommerce’),
    ‘desc_tip’ =>’true’,
    ‘description’ =>__(‘Enter location’,’woocommerce’)
    ));
    // Create Hotel name
    woocommerce_wp_text_input(
    array(
    ‘id’ => ‘ayg_hotel’,
    ‘label’ => __(‘hotel’, ‘woocommerce’)
    ));
    woocommerce_wp_text_input(
    array(
    ‘id’ => ‘ayg_hotel_price’,
    ‘label’ => __(‘hotel price’, ‘woocommerce’),
    ‘type’ => ‘number’,
    ‘custom_attributes’ => array(
    ‘step’ => ‘any’,
    ‘min’ => ‘0’
    )
    ));
    woocommerce_wp_text_input(
    array(
    ‘id’ => ‘ayg_mark_up’,
    ‘label’ => __(‘Mark Up’, ‘woocommerce’),
    ‘type’ => ‘number’,
    ‘custom_attributes’ => array(
    ‘step’ => ‘any’,
    ‘min’ => ‘0’
    )
    ));

    }
    add_action( ‘woocommerce_process_product_meta’, ‘ayg_save_custom_settings’ );
    function ayg_save_custom_settings( $post_id ){
    //via
    $woocommerce_via = $_POST[‘ayg_via’];
    if( !empty( $woocommerce_via ) )
    update_post_meta( $post_id, ‘ayg_via’, esc_attr( $woocommerce_via ) );
    // location
    $woocommerce_location = $_POST[‘ayg_location’];
    if( !empty( $woocommerce_location ) )
    update_post_meta( $post_id, ‘ayg_location’, esc_attr( $woocommerce_location ) );
    // hotel name
    $woocommerce_hotel = $_POST[‘ayg_hotel’];
    if( !empty( $woocommerce_hotel ) )
    update_post_meta( $post_id, ‘ayg_hotel’, esc_attr( $woocommerce_hotel ) );
    // hotel price
    $woocommerce_hotel_price = $_POST[‘ayg_hotel_price’];
    if( !empty( $woocommerce_hotel_price ) )
    update_post_meta( $post_id, ‘ayg_hotel_price’, esc_attr( $woocommerce_hotel_price ) );
    // Mark Up
    $woocommerce_markup = $_POST[‘ayg_mark_up’];
    if( !empty( $woocommerce_markup ) )
    update_post_meta( $post_id, ‘ayg_mark_up’, esc_attr( $woocommerce_markup ) );
    add_action( ‘woocommerce_product_write_panel_tabs’, ‘woo_add_custom_admin_product_tab’ );
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can echo out any data saved in post meta fields by using:

    get_post_meta( $post_id, $key, $single );

    In your case, to output the “markup” (As commented in code above):

    echo get_post_meta($post_id, 'ayg_mark_up', true);

    See here for documentation on get_post_meta();

    Moderator bcworkz

    (@bcworkz)

    You said the data is “stored to my rate table”. I assume there is more rate information than the price and markup stored in post meta, and this data is in some kind of separate, custom table.

    You’ll need to use $wpdb methods to access your custom table. Exactly how that is done depends on how your rate data relates to the product posts.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘metadata database’ is closed to new replies.