Ask your WordPress questions! Pay money and get answers fast! (more info)

Shortcode within a shortcode / Landing site function WordPress

  • REFUNDED

I have most of this working, but only need the finishing touches.
I use Cart66 on my website. Cart66 has a shortcode that you can place on your receipt page which is as [[LINK href="http://cart66.com/2011/post_sale-shortcode/"]]shown here[[/LINK]]

I also have CubePoints, which i want to use to reward a customer who just purchased something. This customer would automatically be shown the receipt page and the post-sale shortcode would fire only one time. If a customer re-visits the page or refreshes, anything inside the post-sale shortcode is ignored.

So to award the customer with 1000 the points, the following function needs to be run:

<?php
if( function_exists('cp_alterPoints') && is_user_logged_in() ){
cp_alterPoints(cp_currentUser(), 1000);

} ?>



So basically, i have to run to add points function within this shortcode:

[post_sale] [/post_sale]

I have tried the plugin PHP in post, and pasted that function in the setting page, and then run it as such on the receipt page

[post_sale]
[php function=1]
[/post_sale]

But it does not work. With any run php codes in wordpress post plugins i cannot get it to work either.

I think the below code is responsible for the post-sale shortcode in cart66 (found in cart66's php files). If anyone can find this usefull to write a new function for me.


public function postSale($attrs, $content='null') {
$postSale = false;
if(isset($_GET['ouid'])) {
$order = new Cart66Order();
$order->loadByOuid($_GET['ouid']);
if($order->viewed == 0) {
$postSale = true;
}
}
$content = $postSale ? $content : '';
return do_shortcode($content);
}




Thanks!

Answers (2)

2012-10-23

John Cotton answers:

I've no idea whether this will work, but you could try this in your theme functions file:


<?php

// get rid the current one
remove_shortcode( 'post_sale' );


function my_new_post_sale( $atts ) {

if(isset($_GET['ouid'])) {

$order = new Cart66Order();

$order->loadByOuid($_GET['ouid']);

if($order->viewed == 0) {

if( function_exists('cp_alterPoints') && is_user_logged_in() ){
cp_alterPoints(cp_currentUser(), 1000);

}
}


}
}
add_shortcode( 'post_sale', 'my_new_post_sale' );
?>


oomskaap comments:

The above did not update the points. Could it be because the ouid is dynamically generated by the receipt page? A receipt would look like this

/store/receipt/?ouid=f4578f3f5107fd435ff2f6e2a95c8358


oomskaap comments:

Ignore the above comment. When i use

[post_sale ]

[/post_sale]

On my receipt page, when i enter the above 2 shortcodes (without anything between the two ), the points increase by 1000, but it does so each time the page is refreshed.


oomskaap comments:

I have played around a bit.

It works perfectly when i modify the following core code of cart66:

public function postSale($attrs, $content='null') {
$postSale = false;
if(isset($_GET['ouid'])) {
$order = new Cart66Order();
$order->loadByOuid($_GET['ouid']);
if($order->viewed == 0) {
$postSale = true;
}
}
$content = $postSale ? $content : '';
return do_shortcode($content);
}



I change it to the following:

public function postSale($attrs, $content='null') {
$postSale = false;
if(isset($_GET['ouid'])) {
$order = new Cart66Order();
$order->loadByOuid($_GET['ouid']);
if($order->viewed == 0) {
$postSale = true;
<strong> cp_alterPoints(cp_currentUser(), 1000);</strong>
}
}
$content = $postSale ? $content : '';
return do_shortcode($content);
}


However, it is not that desirable because when the plugin gets updated i lose the changes, and the function is missing the <strong> if( function_exists(‘cp_alterPoints’) && is_user_logged_in() ){</strong> part which i cant get to work with the above set up. The user logged in is not neccesary for the code to work, but its better to check if the user is logged in etc. so i prefer it to be included


oomskaap comments:

OK fully working core code

public function postSale($attrs, $content='null') {
$postSale = false;
if(isset($_GET['ouid'])) {
$order = new Cart66Order();
$order->loadByOuid($_GET['ouid']);
if($order->viewed == 0) {
$postSale = true;
if( function_exists('cp_alterPoints') && is_user_logged_in() ){

cp_alterPoints(cp_currentUser(), 1000);
}
}
}
$content = $postSale ? $content : '';
return do_shortcode($content);
}


Still prefer a non cart66 core edit function.


John Cotton comments:

You're right, you don't want to edit the plugin code...

Have you tried


remove_shortcode( 'post_sale' );

public function my_postSale($attrs, $content='null') {

$postSale = false;

if(isset($_GET['ouid'])) {

$order = new Cart66Order();

$order->loadByOuid($_GET['ouid']);

if($order->viewed == 0) {

$postSale = true;

if( function_exists('cp_alterPoints') && is_user_logged_in() ){



cp_alterPoints(cp_currentUser(), 1000);

}

}

}


$content = $postSale ? $content : '';

return do_shortcode($content);

}
add_shortcode( 'post_sale', 'my_postSale' );


?

I would have thought that would work but, to be honest, I'm not clear how their code is determining whether it is the first time through. $order->viewed == 0 ?

2012-10-23

RNWest answers:

Hi There,
This is very much a long shot because most shopping cart pages are session based and I am not sure how php is fired on refresh or if this is a shortcode in shorcode problem.
But here is what I use in wordpress to use shortcode inside of shortcode in worpdress try...

Add this code to the theme/functions.php
define('FILTERPRIORITY', 10);
add_filter('the_content', 'do_shortcode', FILTERPRIORITY);
add_filter('widget_text', 'do_shortcode', FILTERPRIORITY);


Hope it works