Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shortcode for Contact Form 7 Dynamic Text Extension - CF7DTE is great but sometimes you need a custom shortcode to get product info into the form. https://www.damiencarbery.com/2019/11/shortcode-for-contact-form-7-dynamic-text-extension/
<?php
/*
Plugin Name: CF7DTE shortcode for product sku
Plugin URI: https://www.damiencarbery.com/2019/11/shortcode-for-contact-form-7-dynamic-text-extension/
Description: Custom shortcode to retrieve product sku via the $_POST['product_id']. For use with WooCommerce Quote or Enquiry Contact Form 7 plugin and Contact Form 7 Dynamic Text Extension.
Author: Damien Carbery
Version: 0.1
WC tested up to: 3.8
*/
add_shortcode( 'product_sku', 'dcwd_product_sku_from_produt_id' );
function dcwd_product_sku_from_produt_id() {
$product_id = sanitize_text_field( $_POST[ 'product_id' ] );
$product_sku = get_post_meta( $product_id, '_sku', true );
return $product_sku;
}
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.