0

In my plugin to configure some basic values using a woocommerce function which is creating a select field, but for some reason it generate this error: "Notice: Trying to get property of non-object in /var/www/html/wp-content/plugins/woocommerce/includes/admin/wc-meta-box-functions.php on line 192"

It works but the error message on the screen driving me crazy. I can change value and save and everything is perfectly fine except the message.

function spinna360_nof($noi) {

woocommerce_wp_select( 
    array(
        'id'        => '_select_noi',
        'label'     => __( 'Select number of images: ', 'spinna360' ),
        'selected'  => true,
        'value'     =>  $noi,
        'options'   => [
            '24'        => __( '24', 'spinna360' ),
            '36'        => __( '36', 'spinna360' ),
            '48'        => __( '48', 'spinna360' )
            ]
        )
    );
}

Why? What is the problem?

0

try use global $post; at the beginning of your function

Note that you've to run on a specific hook in order to work. see this post: https://www.ibenic.com/how-to-add-woocommerce-custom-product-fields/

function spinna360_nof() {
$noy=array(
    'id'        => '_select_noi',
    'label'     => __( 'Select number of images: ', 'spinna360' ),
    'selected'  => true,
    'options'   => [
        '24'        => __( '24', 'spinna360' ),
        '36'        => __( '36', 'spinna360' ),
        '48'        => __( '48', 'spinna360' )
        ]
);
woocommerce_wp_select($noy);   
}
add_action( 'woocommerce_product_data_panels', 'spinna360_nof');
  • Hi Andrea, I tried, does not help much :P – Rob D. A. Sep 14 '18 at 15:13
  • on which hook are you runing it? – Andrea Somovigo Sep 14 '18 at 15:23
  • Extend question a little bit please. Don't know what you asking me for :) – Rob D. A. Sep 14 '18 at 15:25
  • I've updated my answer above – Andrea Somovigo Sep 14 '18 at 15:26
  • add_action( 'woocommerce_product_data_panels', 'spinna360_nof') – Rob D. A. Sep 14 '18 at 15:32

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.