Hello, I would like to display the base price in WooCommerce. How does it work?
In order to display the base price for affiliate products, the following hook must be stored as a snippet. After that, WooCommerce will display the price from the affiliate product directly and also the base price (if any).
function cw_change_product_price_display( $price ) {
$woo_id = get_the_ID();
$productid = ATKPTools::get_post_setting( $woo_id, ATKP_PLUGIN_PREFIX . '_sourceproductid' );
if ( $productid != '' && $productid != 0 ) {
$product_list = atkp_product_collection::load( $productid );
if($product_list != null && $product_list->get_main_product() != null) {
$formatter = new atkp_formatter( null, null );
$product =$product_list->get_main_product();
return $formatter->get_pricetext($product, __( '%s', ATKP_PLUGIN_PREFIX ), __( 'Price not available', ATKP_PLUGIN_PREFIX )). ' '. $formatter->get_basepricetext($product);
}
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );