Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AnanthFlycart/769f99928657d792da388a35593d4dbd to your computer and use it in GitHub Desktop.

Select an option

Save AnanthFlycart/769f99928657d792da388a35593d4dbd to your computer and use it in GitHub Desktop.
CUW: NOC shortcode
add_filter('cuw_noc_action_display_locations', function($locations) {
$locations['cuw_noc_shortcode'] = esc_html__("Use a shortcode [cuw_noc]", 'checkout-upsell-woocommerce');
return $locations;
});
add_shortcode('cuw_noc', function() {
ob_start();
if (!empty($_GET['key']) && function_exists('wc_get_order_id_by_order_key')) {
$order_id = wc_get_order_id_by_order_key(sanitize_key($_GET['key']));
$order = wc_get_order($order_id);
if (!empty($order) && method_exists('CUW\App\Modules\Campaigns\NOC', 'getActionsHtml')) {
echo \CUW\App\Modules\Campaigns\NOC::getActionsHtml('cuw_noc_shortcode', $order);
}
}
return ob_get_clean();
});
add_action('wp_head', function () {
global $wp, $post;
if (!empty($post) && !empty($wp) && isset($post->post_type) && $post->post_type == 'page') {
if (has_shortcode($post->post_content, 'cuw_noc')) {
$wp->query_vars['order-received'] = 'order-received';
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment