Below, you’ll find a detailed guide on how to add the Upsell Order Bump Offer for WooCommerce Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Upsell Order Bump Offer for WooCommerce Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Upsell Order Bump Offer for WooCommerce Plugin and the shortcodes it provides:
"Upsell Order Bump Offer for WooCommerce is a dynamic plugin designed to increase sales and Average Order Value (AOV). It enables easy upsell and cross-sell offers on the checkout page."
- [wps_order_details]
Upsell Order Bump Offer for WooCommerce [wps_order_details] Shortcode
The Upsell Order Bump Offer for WooCommerce plugin shortcode, ‘wps_order_details’, is designed to display order details. This shortcode retrieves the order ID stored in the WooCommerce session. If the order ID exists, it loads the WooCommerce template for order details and displays them. After use, the value is removed from the session.
Shortcode: [wps_order_details]
Examples and Usage
Basic example – The Upsell Order Bump Offer for WooCommerce plugin allows you to display order details using the shortcode ‘wps_order_details’. This shortcode does not require any parameters.
[wps_order_details /]
Advanced examples
While the basic use of the shortcode does not require any parameters, you can extend its functionality by using PHP to add parameters to the ‘wps_display_order_details_shortcode’ function. For example, you can add a ‘show_only_total’ parameter to only display the total cost of the order.
First, modify the PHP function:
function wps_display_order_details_shortcode( $atts ) {
$atts = shortcode_atts( array(
'show_only_total' => false
), $atts );
if ( ! is_admin() ) {
$stored_order_id = WC()->session->get( 'custom_order_id' );
$order_id = absint( $stored_order_id );
if ( ! empty( $order_id ) ) {
ob_start();
// Load WooCommerce templates for order details.
if ( $atts['show_only_total'] ) {
wc_get_template( 'order/order-details-total.php', array( 'order_id' => $order_id ) );
} else {
wc_get_template( 'order/order-details.php', array( 'order_id' => $order_id ) );
}
// Now that you've used the value, you can remove it from the session.
return ob_get_clean();
}
}
}
Then, use the modified shortcode in your content:
[wps_order_details show_only_total=true /]
This will display only the total cost of the order, instead of the full order details.
PHP Function Code
In case you have difficulties debugging what causing issues with [wps_order_details]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wps_order_details', array( $this, 'wps_display_order_details_shortcode' ), 10 );
Shortcode PHP function:
function wps_display_order_details_shortcode() {
if ( ! is_admin() ) {
$stored_order_id = WC()->session->get( 'custom_order_id' );
$order_id = absint( $stored_order_id );
if ( ! empty( $order_id ) ) {
ob_start();
// Load WooCommerce templates for order details.
wc_get_template( 'order/order-details.php', array( 'order_id' => $order_id ) );
// Now that you've used the value, you can remove it from the session.
return ob_get_clean();
}
}
}
Code file location:
upsell-order-bump-offer-for-woocommerce/upsell-order-bump-offer-for-woocommerce/public/class-upsell-order-bump-offer-for-woocommerce-public.php
Conclusion
Now that you’ve learned how to embed the Upsell Order Bump Offer for WooCommerce Plugin shortcode, 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.
Leave a Reply