0

I am using the flat rates shipping plugin in cartthrob. I need to add a description for the shipping product, so I managed to get this far:

I added the following in cartthrob_shipping_flat_rates.php

            array(
                'name' => 'shipping_product_description',
                'short_name' => 'product_description',
                'type' => 'text'
            ),

This code added the fields I need to input a description to each shipping product i.e.(arrives within 7-14 days, arrives within 3 days etc.).

https://dl.dropboxusercontent.com/u/1348309/shipping.png

My question is, how do I make use of that content. In my template tags I am using the following:

<h3>{rate_title} Shipping</h3>
<h5>{product_description}</h5>

and this is outputting this:

USPS Priority Shipping {product_description}

https://dl.dropboxusercontent.com/u/1348309/shipping-template.png

0

You'd need to return this extra information back to the template through a tag. Creating the new settings array as you have done will only store the information against your plugin, not automatically return it to the template.

I haven't tested this, but here's what I think you'd need to add to the plugin.

In the initialize() function, around line 59 you should see:

$this->rate_titles[$rate['short_name']] = $rate['title'];

Add:

$this->product_description[$rate['short_name']] = $rate['product_description'];

You should then be able to create a new tag variable in the plugin_shipping_options() function towards the end of the plugin.

public function plugin_shipping_options()
{
    $options = array();

    foreach ($this->rates as $rate_short_name => $price)
    {
        $options[] = array(
            'rate_short_name' => $rate_short_name,
            'price' => $price,
            'rate_price' => $price,
            'rate_title' => $this->rate_titles[$rate_short_name],
            'product_description' => $this->rate_titles[$product_description]
        );
    }

    return $options;
}

You should then have access to the tag {product_description} in your template. As I said, not tested this so can't be sure it would work.

Also, I'd recommend changing your tag to something like shipping_rate_description to avoid any potential confusion with any channel entries tags that might be of a similar name.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.