• Resolved Marco Almeida | Webdados

    (@webdados)


    Notice: Trying to get property ‘slug’ of non-object in /home/***/public_html/wp-content/plugins/woocommerce-apg-weight-and-postcodestatecountry-shipping/apg-shipping.php on line 207

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Art Project Group

    (@artprojectgroup)

    Hi Marco, do you have attributes in your store?

    Best regards.

    Good morning, same error here, : Attempt to read property “slug” on array in line 208. No idea why this error is.

    Plugin Author Art Project Group

    (@artprojectgroup)

    This line processes the product attributes to store and display them in the plugin options and filter the rates according to their configuration.

    Check your attributes since we haven’t been able to replicate the issue.

    Best regards.

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    We do have attributes.

    Check your attributes since we haven’t been able to replicate the issue.

    Check what exactly?

    Plugin Author Art Project Group

    (@artprojectgroup)

    Check if you have any attributes without a slug.

    Best regards.

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    The error is not that the “slug” property is empty but rather the plugin trying access a property to something that it’s not an object.

    I think this happens because of WPML. wc_get_attribute_taxonomies() is returning the attributes/taxonomies twice and the first time you run get_terms() it returns an error:

    object(WP_Error)#25949 (3) {
    ["errors"]=>array(1) {["invalid_taxonomy"]=>array(1) {
    [0]=>string(20) "Taxonomia inválida."
    }
    }
    ["error_data"]=>array(0) {
    ["additional_data":protected]=>array(0) {}
    }

    Before running get_terms() you need to check if $atributo is not an WP_Error: https://developer.www.ads-software.com/reference/functions/is_wp_error/

    I can submit a PR if you have GitHub.

    Plugin Author Art Project Group

    (@artprojectgroup)

    Thanks Marco, the truth is that we have not tested it with WPML and that’s why I have not been able to replicate the problem.

    We’ll check it as soon as possible.

    Best regards.

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    Just check for WP_Error ??

    Plugin Author Art Project Group

    (@artprojectgroup)

    Can you try this code?

    //Función que lee y devuelve los atributos
    public function apg_shipping_dame_atributos() {
    	if ( wc_get_attribute_taxonomies() ) {
    		foreach ( wc_get_attribute_taxonomies() as $atributo ) {
    			if ( ! is_wp_error( $atributo ) ) {
    				$terminos   = get_terms( array( 'taxonomy' => 'pa_' . $atributo->attribute_name ) );
    				foreach( $terminos as $termino ) {
    					$this->atributos[ esc_attr( $atributo->attribute_label ) ][ 'pa_' . $atributo->attribute_name . "-" . $termino->slug ] = $termino->name;
    				}		
    			}
    		}
    	}
    }

    If it solves it for you we’ll add it in the next update.

    Best regards.

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    I have a typo on a previous message. It’s $terminos you should look into, not asas.

    Here’s the correct code:

    public function apg_shipping_dame_atributos() {
    if ( wc_get_attribute_taxonomies() ) {
    foreach ( wc_get_attribute_taxonomies() as $atributo ) {
    $terminos = get_terms( array( 'taxonomy' => 'pa_' . $atributo->attribute_name ) );
    if ( ! is_wp_error( $terminos ) ) {
    foreach( $terminos as $termino ) {
    $this->atributos[ esc_attr( $atributo->attribute_label ) ][ 'pa_' . $atributo->attribute_name . "-" . $termino->slug ] = $termino->name;
    }
    }
    }
    }
    }

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    Is there a reason to get all this attributes on every page load?

    Also all this:

    $this->apg_shipping_dame_datos_de_producto( 'categorias_de_producto' ); //Obtiene todas las categorías de producto
    $this->apg_shipping_dame_datos_de_producto( 'etiquetas_de_producto' ); //Obtiene todas las etiquetas de producto
    $this->apg_shipping_dame_clases_de_envio(); //Obtiene todas las clases de envío
    $this->apg_shipping_dame_roles_de_usuario(); //Obtiene todos los roles de usuario
    $this->apg_shipping_dame_metodos_de_envio(); //Obtiene todas los métodos de envío
    $this->apg_shipping_dame_metodos_de_pago(); //Obtiene todos los métodos de pago
    $this->apg_shipping_dame_atributos(); //Obtiene todos los atributos

    It seems to me the plugin is doing a lot of stuff we don’t need unless we’re inside calculate_shipping. Shouldn’t all this calls be done only when needed?

    Plugin Author Art Project Group

    (@artprojectgroup)

    Thanks Marco. We will add the code in the next update.

    That’s to use it in the payment method configuration page, if it isn’t loaded in the init they do not collect data or give errors. It isn’t the most optimal, but it has been the only way in which we have been able to collect the information without generating errors.

    Best regards.

    Plugin Author Art Project Group

    (@artprojectgroup)

    We add the code you propose and improve performance by removing the execution of all these functions from the init.

    Thank you Marco.

    Best Regards

    Thread Starter Marco Almeida | Webdados

    (@webdados)

    So awesome!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘PHP notice apg-shipping.php on line 207’ is closed to new replies.