0
a:3:{
  i:0;a:2:{s:21:"wwsd_percent_discount";s:2:"10";s:25:"wwsd_minimum_discount_qrt";s:2:"20";}
  i:1;a:2:{s:21:"wwsd_percent_discount";s:2:"20";s:25:"wwsd_minimum_discount_qrt";s:2:"50";}
  i:2;a:2:{s:21:"wwsd_percent_discount";s:2:"30";s:25:"wwsd_minimum_discount_qrt";s:3:"100";}
}

I want to get 10, 20, 30 from wwsd_percent_discount.

I wrote this code:

$getId = $product->get_id();
global $wpdb;    
$result = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE post_id='$getId' AND meta_key ='wwsd_wholesale_discount_data'");

if ( !empty( $result ) ) {

    foreach ( $result as $r ) {
        echo "<br>".$r->meta_value;
    }
}
1

If the data you placed at the beginning of your question is the result of your database query (I'm unsure by how your question is worded), you will want to take that query result and use the PHP function unserialize() to convert that data to an array, then you can access your data from that array.

Your serialized data will become at array that looks like this:

Array
(
    [0] => Array
        (
            [wwsd_percent_discount] => 10
            [wwsd_minimum_discount_qrt] => 20
        )

    [1] => Array
        (
            [wwsd_percent_discount] => 20
            [wwsd_minimum_discount_qrt] => 50
        )

    [2] => Array
        (
            [wwsd_percent_discount] => 30
            [wwsd_minimum_discount_qrt] => 100
        )
)
|improve this answer|||||
  • @user3748874 Please click the checkmark by my answer to accept it as the solution if this worked out for you. :) – Talk Nerdy To Me Jan 29 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.