Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback for the woocommerce filter "woocommerce_cart_item_permalink" is not implemented correctly. #1112

Open
MaximMitrofanov opened this issue Sep 18, 2024 · 0 comments

Comments

@MaximMitrofanov
Copy link

MaximMitrofanov commented Sep 18, 2024

Hello there,
We are currently developing a site that uses tutor as an LMS but also is not the main focus of the website,
Since we have different products our minicart is bugged due to your code, the filter "woocommerce_cart_item_permalink" does not return a permalink for normal products, this is due how the callback is implemented.

tutor\classes\WooCommerce.php:748

public function tutor_update_product_url( $permalink, $cart_item ) {

		$woo_product_id = $cart_item['product_id'];
		$product_meta   = get_post_meta( $woo_product_id );

		if ( isset( $product_meta['_tutor_product'] ) && $product_meta['_tutor_product'][0] ) {

			global $wpdb;
			$table   = $wpdb->base_prefix . 'postmeta';
			$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$table} WHERE meta_key = '_tutor_course_product_id' AND meta_value = %d ", $woo_product_id ) ); //phpcs:ignore

			if ( $post_id ) {
				$data = get_post_permalink( $post_id );
				return $data;
			}
		}

		// Does not exist
		 return $permalink; // Should return the original permalink
}

As you can see, the function tries to retrieve the associated course and changes the link to the course link if it has the _tutor_product meta, but if it does not, it voids.
Please return the original permalink as I've noted in the comments in the code provided above.

The original code:

	public function tutor_update_product_url( $permalink, $cart_item ) {

		$woo_product_id = $cart_item['product_id'];
		$product_meta   = get_post_meta( $woo_product_id );

		if ( isset( $product_meta['_tutor_product'] ) && $product_meta['_tutor_product'][0] ) {

			global $wpdb;
			$table   = $wpdb->base_prefix . 'postmeta';
			$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$table} WHERE meta_key = '_tutor_course_product_id' AND meta_value = %d ", $woo_product_id ) ); //phpcs:ignore

			if ( $post_id ) {
				$data = get_post_permalink( $post_id );
				return $data;
			}
		}
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant