Trying to create a custom variable product type, but get wrong price in cart
-
Hi. I’m currently trying to create a custom product type that extends
WC_Product_Variable
, but my problem are in cart: when cart render the items, it does not show correct item price of the variation, instead it show the ‘base’ price of the variable product.This is the current code of my custom product type.
<?php if ( ! defined( 'ABSPATH' ) ) { return; } include_once INC_DIR . 'woocommerce/Sams_Salsa_Common_Slugs.php'; /** * Class representation of Salsa Pack product type. * * @author Moisés González <[email protected]> */ class WC_Salsa_Pack_Product_Type extends WC_Product_Variable implements Samsa_Salsa_Common_Slugs { /** * Product type * * @var string */ protected $product_type = self::SALSA_PACK_SLUG; public function __construct( $product ) { parent::__construct( $product ); } /** * Override get_type WC_Product method. * * @return string */ public function get_type() { return $this->product_type; } /** * Override add_to_cart_url WC_Product method to * return the product permalink. * * @return string */ public function add_to_cart_url() { $url = get_permalink( $this->get_id() ); return apply_filters( 'woocommerce_product_add_to_cart_url', $url, $this ); } /** * Override add_to_cart_text WC_Product method. * * @return string */ public function add_to_cart_text() { $text = __( 'Choice your Salsas', 'sams-famous-salsa' ); return apply_filters( 'woocommerce_product_add_to_cart_text', $text, $this ); } }
Also, I figured out that normals variable product instance
WC_Product_Variation
in cart, but variations of my product type still instanceWC_Salsa_Pack_Product_Type
. The is a way to change this behaviour?EDIT: Is a point bweteen Cart and Checkout. Seems that
variation_id
is not saved correctly and don’t get stored correctly in Cart session.- This topic was modified 4 years, 6 months ago by . Reason: Miss formatting
- This topic was modified 4 years, 6 months ago by .
- This topic was modified 4 years, 6 months ago by .
- This topic was modified 4 years, 6 months ago by .
- This topic was modified 4 years, 6 months ago by .
- This topic was modified 4 years, 6 months ago by . Reason: Add hint
- The topic ‘Trying to create a custom variable product type, but get wrong price in cart’ is closed to new replies.