soflyy / breakdance-bugs

Bug reports from Breakdance users.
40 stars 6 forks source link

global $product returns a string when used in a shortcode in a Breakdance Woo Product Single Template. #1038

Open adkoen opened 8 months ago

adkoen commented 8 months ago
  1. Create this shortcode and use it on a WooCommerce product single template:
SCR-20240114-mkbq
  1. You'll get an error saying: Call to a member function get_id() on string

So the problem is that using the global $product in a shortcode in a woocommerce single template returns a string instead of the product object. It looks like the loop of Breakdance somehow causes this.

andyfo commented 7 months ago

I think I just stumbled upon the same issue.

Using a "product is on sale" condition in a single product template causes the following error:

Call to a member function is_on_sale() on string in /home/.../wp-content/plugins/breakdance/plugin/themeless/rules/woocommerce/product-sale.php:38

The source code of the function where the error is thrown:

function ($operand, $value): bool {
    global $product;
    if (!$product) {
        return false;
    }
    /** @var \WC_Product $product */
    $product = $product;
    if ($value === 'on_sale') {
        return $product->is_on_sale();
    }
    if ($value === 'not_on_sale') {
        return !$product->is_on_sale();
    }
    return false;
}

Looks like global $product; produces a string.