WordPress Simple Shopping Cart Shortcodes

Below, you’ll find a detailed guide on how to add the WordPress Simple Shopping Cart Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WordPress Simple Shopping Cart Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the WordPress Simple Shopping Cart Plugin and the shortcodes it provides:

Plugin Icon
WordPress Simple Shopping Cart

"WordPress Simple Shopping Cart is a user-friendly plugin that seamlessly integrates PayPal, making it easy for your website visitors to shop and complete transactions. Boost your e-commerce efficiency today!"

★★★★☆ (189) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [show_wp_shopping_cart]
  • [always_show_wp_shopping_cart]
  • [wp_cart_button]
  • [wp_cart_display_product]
  • [wp_compact_cart]
  • [wp_compact_cart2]

WordPress Simple Shopping Cart [show_wp_shopping_cart] Shortcode

The ‘show_wp_shopping_cart’ shortcode from the WordPress Simple PayPal Shopping Cart plugin provides a dynamic display of the user’s shopping cart. When used, this shortcode calls the function ‘show_wp_shopping_cart_handler’. This function checks if the cart is not empty. If it contains items, it outputs the cart’s content using the ‘print_wp_shopping_cart’ function.

Shortcode: [show_wp_shopping_cart]

Examples and Usage

Basic example – This shortcode displays the shopping cart if it is not empty.

[show_wp_shopping_cart]

PHP Function Code

In case you have difficulties debugging what causing issues with [show_wp_shopping_cart] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('show_wp_shopping_cart', 'show_wp_shopping_cart_handler');

Shortcode PHP function:

function show_wp_shopping_cart_handler( $atts ) {
    $wspsc_cart= WSPSC_Cart::get_instance();
	$output = "";    
	if ( $wspsc_cart->cart_not_empty() ) {
	$output = print_wp_shopping_cart( $atts );
    }
    return $output;
}

Code file location:

wordpress-simple-paypal-shopping-cart/wordpress-simple-paypal-shopping-cart/wp_shopping_cart_shortcodes.php

WordPress Simple Shopping Cart [always_show_wp_shopping_cart] Shortcode

The ‘always_show_wp_shopping_cart’ shortcode is a function in the WordPress Simple PayPal Shopping Cart plugin. It displays the shopping cart on your site at all times. The related PHP code ‘always_show_cart_handler’ returns the print_wp_shopping_cart function, which renders the cart.

Shortcode: [always_show_wp_shopping_cart]

Examples and Usage

Basic example – The shortcode below will display the shopping cart, which is always visible on the page, regardless of whether there are items in it or not.

[always_show_wp_shopping_cart]

PHP Function Code

In case you have difficulties debugging what causing issues with [always_show_wp_shopping_cart] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('always_show_wp_shopping_cart', 'always_show_cart_handler');

Shortcode PHP function:

function always_show_cart_handler( $atts ) {
    return print_wp_shopping_cart( $atts );
}

Code file location:

wordpress-simple-paypal-shopping-cart/wordpress-simple-paypal-shopping-cart/wp_shopping_cart_shortcodes.php

WordPress Simple Shopping Cart [wp_cart_button] Shortcode

The WordPress Simple Paypal Shopping Cart shortcode is a useful tool for creating a customizable shopping cart. It uses the shortcode ‘wp_cart_button’ to add a product to the cart. The shortcode requires product name and price attributes. If these are absent, it displays an error. It also accepts optional attributes like shipping cost and product variables.

Shortcode: [wp_cart_button]

Parameters

Here is a list of all possible wp_cart_button shortcode parameters and attributes:

  • name – specifies the product name for the shopping cart item
  • item_number – assigns a unique number to the product
  • price – sets the product’s selling price
  • shipping – designates the shipping cost for the product
  • var1, var2, var3 – allows for additional product variables
  • thumbnail – provides a thumbnail image for the product
  • button_text – customizes the text displayed on the cart button
  • button_image – sets a custom image for the cart button
  • file_url – links to a downloadable file for the product
  • stamp_pdf – enables PDF stamping for the product

Examples and Usage

Basic example – A simple usage of the shortcode to add a product with its name and price to the shopping cart.

[wp_cart_button name="Test Product" price="29.99"]

Advanced examples

Adding a product with additional parameters like shipping cost, variation, and thumbnail image.

[wp_cart_button name="Test Product" price="29.99" shipping="4.99" var1="Size|Small|Medium|Large" thumbnail="http://example.com/images/product.jpg"]

Adding a product with a custom button text and button image.

[wp_cart_button name="Test Product" price="29.99" button_text="Add to Cart" button_image="http://example.com/images/add-to-cart.png"]

Adding a digital product with a file URL for instant download after purchase.

[wp_cart_button name="Test eBook" price="9.99" file_url="http://example.com/files/ebook.pdf"]

Adding a product with PDF stamping enabled. The ‘stamp_pdf’ parameter is set to ‘true’ to enable this feature.

[wp_cart_button name="Test eBook" price="9.99" file_url="http://example.com/files/ebook.pdf" stamp_pdf="true"]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp_cart_button] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wp_cart_button', 'wp_cart_button_handler');

Shortcode PHP function:

function wp_cart_button_handler($atts){
	extract(shortcode_atts(array(
		'name' => '',
                'item_number' =>'',
		'price' => '',
		'shipping' => '0',
		'var1' => '',
		'var2' => '',
		'var3' => '',
                'thumbnail' => '',
                'button_text' => '',
                'button_image' => '',
                'file_url' => '',
                'stamp_pdf' => '',
	), $atts));

	if(empty($name)){
            return '<div style="color:red;">'.(__("Error! You must specify a product name in the shortcode.", "wordpress-simple-paypal-shopping-cart")).'</div>';
	}
	if(empty($price)){
            return '<div style="color:red;">'.(__("Error! You must specify a price for your product in the shortcode.", "wordpress-simple-paypal-shopping-cart")).'</div>';
	}
        $price = wspsc_strip_char_from_price_amount($price);
        $shipping = wspsc_strip_char_from_price_amount($shipping);

	return print_wp_cart_button_for_product($name, $price, $shipping, $var1, $var2, $var3, $atts);
}

Code file location:

wordpress-simple-paypal-shopping-cart/wordpress-simple-paypal-shopping-cart/wp_shopping_cart_shortcodes.php

WordPress Simple Shopping Cart [wp_cart_display_product] Shortcode

The ‘wp_cart_display_product’ shortcode is used to display a product with its details on a WordPress site. It extracts attributes like name, price, thumbnail, and more from the product data. It checks for necessary details like name, price, and thumbnail. If these are missing, it throws an error. It also formats the price, creates a button for the cart, and finally displays the product.

Shortcode: [wp_cart_display_product]

Parameters

Here is a list of all possible wp_cart_display_product shortcode parameters and attributes:

  • name – the name of the product you are selling
  • item_number – a unique identifier for the product
  • price – the cost of the product
  • shipping – the shipping cost for the product
  • var1 – a variable parameter for the product
  • var2 – a second variable parameter for the product
  • var3 – a third variable parameter for the product
  • thumbnail – the URL of the product image
  • thumb_target – the URL the thumbnail image should link to
  • thumb_alt – the alternative text for the product image
  • description – a brief description of the product
  • button_text – the text that appears on the purchase button
  • button_image – the image that appears on the purchase button
  • file_url – the URL of the downloadable product file
  • stamp_pdf – a parameter for stamping PDF files

Examples and Usage

Basic example – Displaying a product with its name, price, and thumbnail image.

[wp_cart_display_product name="Test Product" price="25" thumbnail="https://example.com/images/test_product.jpg" /]

Advanced examples

Displaying a product with additional attributes such as item number, shipping cost, variable options, and a custom button text.

[wp_cart_display_product name="Test Product" item_number="123" price="25" shipping="5" var1="Size|Small|Medium|Large" var2="Color|Red|Blue|Green" button_text="Add to Cart" thumbnail="https://example.com/images/test_product.jpg" /]

Displaying a product with a description, a target URL for the thumbnail, and an alternate text for the thumbnail.

[wp_cart_display_product name="Test Product" price="25" thumbnail="https://example.com/images/test_product.jpg" thumb_target="https://example.com/test_product" thumb_alt="Test Product Image" description="This is a test product." /]

Displaying a product with a digital file URL and the option to stamp the PDF file.

[wp_cart_display_product name="Test Product" price="25" thumbnail="https://example.com/images/test_product.jpg" file_url="https://example.com/files/test_product.pdf" stamp_pdf="yes" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp_cart_display_product] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wp_cart_display_product', 'wp_cart_display_product_handler');

Shortcode PHP function:

function wp_cart_display_product_handler($atts)
{
    extract(shortcode_atts(array(
        'name' => '',
        'item_number' =>'',
        'price' => '',
        'shipping' => '0',
        'var1' => '',
        'var2' => '',
        'var3' => '',
        'thumbnail' => '',
        'thumb_target' => '',
        'thumb_alt' => '',
        'description' => '',
        'button_text' => '',
        'button_image' => '',
        'file_url' => '',
        'stamp_pdf' => '',
    ), $atts));

    if(empty($name)){
        return '<div style="color:red;">'.(__("Error! You must specify a product name in the shortcode.", "wordpress-simple-paypal-shopping-cart")).'</div>';
    }
    if(empty($price)){
        return '<div style="color:red;">'.(__("Error! You must specify a price for your product in the shortcode.", "wordpress-simple-paypal-shopping-cart")).'</div>';
    }
    if(empty($thumbnail)){
        return '<div style="color:red;">'.(__("Error! You must specify a thumbnail image for your product in the shortcode.", "wordpress-simple-paypal-shopping-cart")).'</div>';
    }
    if(empty($thumb_alt)){
        //Use the product name as alt if the thumb_alt is not defined.
        $thumb_alt = $name;
    }

    $price = wspsc_strip_char_from_price_amount($price);
    $shipping = wspsc_strip_char_from_price_amount($shipping);
    $thumbnail_code = '<img src="'.esc_url_raw($thumbnail).'" alt="'.esc_attr( $thumb_alt ).'">';
    if(!empty($thumb_target) && preg_match("/http/", $thumb_target)){
        $thumbnail_code = '<a href="'.esc_url_raw($thumb_target).'"><img src="'.esc_url_raw($thumbnail).'" alt="'.esc_attr( $thumb_alt ).'"></a>';
    }
    $thumbnail_code = apply_filters('wspsc_product_box_thumbnail_code', $thumbnail_code, $atts);
    $currency_symbol = WP_CART_CURRENCY_SYMBOL;
    $formatted_price = print_payment_currency($price, $currency_symbol);
    $button_code = print_wp_cart_button_for_product($name, $price, $shipping, $var1, $var2, $var3, $atts);

    $display_code = <<<EOT
    <div class="wp_cart_product_display_box_wrapper">
    <div class="wp_cart_product_display_box">
        <div class="wp_cart_product_thumbnail">
            $thumbnail_code
        </div>
        <div class="wp_cart_product_display_bottom">
            <div class="wp_cart_product_name">
                $name
            </div>
            <div class="wp_cart_product_description">
                $description
            </div>
                <div class="wp_cart_product_price">
                $formatted_price
            </div>
                <div class="wp_cart_product_button">
                $button_code
                </div>
            </div>
    </div>
    </div>
EOT;
    return $display_code;
}

Code file location:

wordpress-simple-paypal-shopping-cart/wordpress-simple-paypal-shopping-cart/wp_shopping_cart_shortcodes.php

WordPress Simple Shopping Cart [wp_compact_cart] Shortcode

The ‘wp_compact_cart’ shortcode from the WordPress Simple PayPal Shopping Cart plugin is designed to display a compact shopping cart on your website. This shortcode retrieves the total quantity of items present in the cart and their total cost. If the cart is empty, it displays a “Cart is empty” message. If items are present, it shows the total number of items, their total cost, and a “View Cart” button.

Shortcode: [wp_compact_cart]

Examples and Usage

Basic example – The following example uses the ‘wp_compact_cart’ shortcode to display the compact cart. This will show the number of items in the cart and the total price.

[wp_compact_cart /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp_compact_cart] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wp_compact_cart', 'wspsc_compact_cart_handler');

Shortcode PHP function:

function wspsc_compact_cart_handler($args)
{
    $wspsc_cart = WSPSC_Cart::get_instance();
    $num_items = $wspsc_cart->get_total_cart_qty();
    $curSymbol = WP_CART_CURRENCY_SYMBOL;
    $checkout_url = get_option('cart_checkout_page_url');

    $output = "";
    $output .= '<div class="wpsps_compact_cart wpsps-cart-wrapper">';
    $output .= '<div class="wpsps_compact_cart_container">';
    if($num_items>0){
            $cart_total = $wspsc_cart->get_total_cart_sub_total();
            $item_message = ($num_items <= 1) ? __("Item", "wordpress-simple-paypal-shopping-cart") : __("Items", "wordpress-simple-paypal-shopping-cart");
            $output .= $num_items . " " . $item_message;
            $output .= '<span class="wpsps_compact_cart_price"> '. print_payment_currency($cart_total,$curSymbol).'</span>';
            if(!empty($checkout_url)){
                $output .= '<a class="wpsps_compact_cart_co_btn" href="'.$checkout_url.'">'.__("View Cart", "wordpress-simple-paypal-shopping-cart").'</a>';
            }
    }
    else{
            $cart_total = 0;
            $output .= __("Cart is empty", "wordpress-simple-paypal-shopping-cart");
            $output .= '<span class="wpsps_compact_cart_price"> '. print_payment_currency($cart_total,$curSymbol).'</span>';
    }
    $output .= '</div>';
    $output .= '</div>';
    return $output;
}

Code file location:

wordpress-simple-paypal-shopping-cart/wordpress-simple-paypal-shopping-cart/wp_shopping_cart_shortcodes.php

WordPress Simple Shopping Cart [wp_compact_cart2] Shortcode

The ‘wp_compact_cart2’ shortcode is used to display a compact version of the shopping cart, showing the total quantity of items. It generates a link to the checkout page if the URL is set. Otherwise, it simply displays the number of items. It also adjusts the item message based on the quantity.

Shortcode: [wp_compact_cart2]

Examples and Usage

Basic example – Displays the compact cart with the number of items in the cart.

[wp_compact_cart2 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp_compact_cart2] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wp_compact_cart2', 'wspsc_compact_cart2_handler');

Shortcode PHP function:

function wspsc_compact_cart2_handler($args)
{
    $wspsc_cart = WSPSC_Cart::get_instance();
    $num_items = $wspsc_cart->get_total_cart_qty();
    $checkout_url = get_option('cart_checkout_page_url');
    //$curSymbol = WP_CART_CURRENCY_SYMBOL;
    //$cart_total = wpspc_get_total_cart_sub_total();

    $output = "";
    $output .= '<div class="wspsc_compact_cart2 wpsps-cart-wrapper">';
    $output .= '<div class="wspsc_compact_cart2_container">';

    $output .= '<div class="wspsc_compact_cart2_inside">';
    $item_message = ($num_items <= 1) ? __("Item", "wordpress-simple-paypal-shopping-cart") : __("Items", "wordpress-simple-paypal-shopping-cart");

    if(!empty($checkout_url)){
        $output .= '<a class="wspsc_compact_cart2_view_cart_link" href="'.$checkout_url.'">'.$num_items . " " . $item_message . '</a>';
    }else{
        $output .= $num_items . " " . $item_message;
    }
    $output .= '</div>';//end of .wspsc_compact_cart2_inside

    $output .= '</div>';//end of .wspsc_compact_cart2_container
    $output .= '</div>';
    return $output;
}

Code file location:

wordpress-simple-paypal-shopping-cart/wordpress-simple-paypal-shopping-cart/wp_shopping_cart_shortcodes.php

Conclusion

Now that you’ve learned how to embed the WordPress Simple Shopping Cart Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *