Hello there.
I am using Joomla 2.5.x and Virtuemart 2.0.16 and i am trying to do this:
I have 2 shipping methods for different product categories. But i need when someone adds to cart products from both categories to hide a specific shipping method.
i found that i have to edit the file in administrator/components/com_virtuemart/plugins/vmpsplugin.php and i wrote something like this:
$cart = VirtueMartCart::getCart(false);
foreach ($cart->products as $product) {
$insidecategory = $product->virtuemart_category_id;
if ($insidecategory == specific id ) {
$mycat++;} else
{$anothercat++;}
}
if (($mycat >=1) && ($anothercat >=1)) {
//code for hiding a specific shipping method
}
Any ideas on this?
I tried this:
$q .= ' AND v.`virtuemart_' . $this->_psType . 'method_id` != id_that_want_to_hide ';
but it hides all shipping methods.
Thank you in advance
I used to do this by hiding the method with css in the cart and ship template to avoid any core changes
in VM3 this is standard in some plugins - (cat choose ship methods)
this is a product id example but would work with cat ids I guess
$prodids = array();
foreach($this->cart->products as $prods){
$prodids[] = $prods->virtuemart_product_id;
}
$allowed_usps = array(19,21,28);//USPS flatrate box allowed product ids
$allowed_ups = array(17,18,26,27);//UPS allowed product ids
$result_usps=array_intersect($allowed_usps,$prodids);
$result_ups=array_intersect($allowed_ups,$prodids);
if($result_usps && $result_ups){
$no_css = '[id^="usps_id"],label[for^="usps_id"],[id^="usps_id"]>br,label[for^="usps_id"]>br';
if($this->cart->virtuemart_shipmentmethod_id == 7){//USPS shipping id
unset($this->cart->virtuemart_shipmentmethod_id);
}
}elseif($result_usps){
$no_css = '[id^="ups_id"],label[for^="ups_id"]';
if($this->cart->virtuemart_shipmentmethod_id == 8){//UPS shipping id
unset($this->cart->virtuemart_shipmentmethod_id);
}
}else{
$no_css = '[id^="usps_id"],label[for^="usps_id"]';
if($this->cart->virtuemart_shipmentmethod_id == 7){//USPS shipping id
unset($this->cart->virtuemart_shipmentmethod_id);
}
}
//GJC
?>
<style type="text/css">
<?php echo $no_css ?>, .vmCartShipmentLogo {
display:none;
}
</style>
2.0.16 is horribly insecure
I finally will do it inside my 3rd party one page checkout. In this plugin there is a shipping template where they produce the shipping methods like this:
foreach ($this->shipments_shipment_rates as $shipment_shipment_rates){
if(is_array($shipment_shipment_rates)) {
foreach ($shipment_shipment_rates as $shipment_shipment_rate) {
echo str_replace('name="virtuemart_shipmentmethod_id"', 'name="virtuemart_shipmentmethod_id" onclick="return ProOPC.setshipment(this);"', $shipment_shipment_rate);
echo '<div class="clear"></div>';
}
This is the default method of showing.
Now here i am trying 2 things and its not working:
1st) i save in foreach the shipment method in a variable:
$myvariable = echo str_replace('name="virtuemart_shipmentmethod_id"', 'name="virtuemart_shipmentmethod_id" onclick="return ProOPC.setshipment(this);"', $shipment_shipment_rate);
and then through strpos i do like this (i am searching for a value that contains the number 3 inside):
if (strpos ($myvariable, 3) !== false) {echo "I found my shipping method"}
For some reason, even if i have shipping method with no 3 number included, i get the non-false result!
Any ideas?
Also, if i manage somehow to make this work, can i echo in non-false state something like: echo '<div style="display:none;"' . $myvariable . '</div>'; ?
In this way if i identify this method then i echo it inside a div with display none style. DO you think it could work?
Thank you in advance