Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
// To the CF7 form add:
// [dynamichidden dynamichidden-cart "cart_contents"]
// In the CF7 Mail add:
// [dynamichidden-cart]
// The "cart_contents" uses this code
add_shortcode( 'cart_contents', 'dcwd_cart_contents' );
function dcwd_cart_contents($atts, $content, $code) {
$cart_contents = array();
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$cart_contents[] = '* ' . $cart_item['data']->get_name();
}
if ( empty( $cart_contents ) ) {
return 'Cart is empty.';
}
else {
return implode( "\n", $cart_contents );
}
}
<label>Name (required)
[dynamictext* dynamictext-customer-name "customer_name"]</label>
<label>Order Number (required)
[dynamictext* dynamictext-order-number "order_number"]</label>
<label>Which Product(s)? (required)
[dynamictext* dynamictext-products "refund_products"]</label>
<label>Why are you requesting a refund?
[textarea refund-reason] </label>
[submit "Send"]
<?php
add_shortcode('customer_name', 'rr_order_details');
add_shortcode('order_number', 'rr_order_details');
add_shortcode('refund_products', 'rr_order_details');
function rr_order_details($atts, $content, $code) {
switch ($code) {
// Use order ID to retrieve customer first and last name.
case 'customer_name':
if (array_key_exists('order', $_GET)) {
$order_id = $_GET['order'];
$order = new WC_Order( $order_id );
if (is_object($order)) {
$name = $order->billing_first_name.' '.$order->billing_last_name;
return $name;
}
}
return '';
break;
// Retrieve the order ID from the url.
case 'order_number':
if (array_key_exists('order', $_GET)) {
$order_id = $_GET['order'];
return $order_id;
}
return '';
break;
case 'refund_products':
// Retrieve the list of products from the url.
if (array_key_exists('products', $_GET)) {
$products = $_GET['products'];
return $products;
}
return '';
break;
default:
break;
}
}
@hurabg

This comment has been minimized.

Copy link

hurabg commented Apr 23, 2019

Hi Damien i tried inserting your but unable to see the result could you please guide further

@damiencarbery

This comment has been minimized.

Copy link
Owner Author

damiencarbery commented Jun 12, 2019

Where did you insert the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.