Do you want to display other templates if they do not have a price? Then this hook is very suitable for this.
These are just two examples. You will find all the details on the Hook on this page.
Output other template if price equals 0
With this hook, for example, you override the original 4567 with the original 1234 if the selling price of the product is 0:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function modify_template_product( $template, $productid, $content ) { if($template == '4567') { require_once ATKP_PLUGIN_DIR.'/includes/atkp_product.php'; $product = atkp_product::load($productid); if($product->salepricefloat == 0) { return '1234'; } } return $template ; } add_filter( 'atkp_modify_template_product', 'modify_template_product', 10, 3); |
Other template if no offers are available
If you want to display a different template, if there are no more offers (which have a selling price), you can use this hook.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
function modify_template_product( $template, $productid, $content ) { if($template == '4567') { require_once ATKP_PLUGIN_DIR.'/includes/atkp_product.php'; $myproduct = atkp_product::load($productid); //Offers section if(!is_array($myproduct->offers)) $offers = array(); else $offers = $myproduct->offers; $offer = new atkp_product_offer(); $offer->shopid= $myproduct->shopid; $offer->link = $myproduct->producturl; $offer->price = $myproduct->saleprice; $offer->pricefloat = $myproduct->salepricefloat; array_push($offers, $offer); $offercount = 0; foreach($offers as $offer) { if($offer->pricefloat == (float)0 || $offer->hideoffer) continue; $offercount++; } if($offercount == 0) return '1234'; } return $template ; } add_filter( 'atkp_modify_template_product', 'modify_template_product', 10, 3); |
Tip: Use a plugin like My Custom Functions or a child theme to build your hooks!