• Resolved sibivfl

    (@sibivfl)


    I am trying to get a custom shortcode working to my Completed Order template, but whatever I do, it doesn’t work.

    Basically I want to be able to add a custom URL to the Completed Order message when changing a status of the order.

    In email message I am getting this

    [canva_link textcolor=#636363 fontfamily=HelveticaNeue,Helvetica,Roboto,Arial,sans-serif]

    instead of the URL I have added to the custom field.

    here is the code for shortcode I am using

    add_filter(
    'yaymail_customs_shortcode',
    function( $shortcode_list, $yaymail_informations, $args = array() ) {
    $shortcode_list['[canva_link]'] = function() use ($args) {
    if (isset($args['order'])) {
    $order = $args['order'];
    $order_id = $order->get_id();

    // Retrieve the Canva link from order meta
    $canva_link = get_post_meta($order_id, '_canva_link', true);

    // Return the link or fallback message
    return $canva_link ? '<a href="' . esc_url($canva_link) . '" target="_blank">' . esc_html($canva_link) . '</a>' : 'No Canva link provided.';
    }

    // Return a placeholder if no order is found (e.g., in editor previews)
    return 'No order found (testing in YayMail editor)';
    };
    return $shortcode_list;
    },
    10,
    3
    );

    and for the Custom field i am using this code

    // Add custom field to order edit page
    add_action('woocommerce_admin_order_data_after_order_details', 'add_canva_link_to_order');
    function add_canva_link_to_order($order) {
    $canva_link = get_post_meta($order->get_id(), '_canva_link', true);
    echo '<div class="form-field form-field-wide">';
    echo '<label for="canva_link">' . __('Canva Link', 'woocommerce') . '</label>';
    echo '<input type="text" id="canva_link" name="canva_link" value="' . esc_attr($canva_link) . '" />';
    echo '<p class="description">' . __('Add the unique Canva link for this order.', 'woocommerce') . '</p>';
    echo '</div>';
    }

    // Save the custom field when the order is updated
    add_action('woocommerce_process_shop_order_meta', 'save_canva_link_for_order');
    function save_canva_link_for_order($order_id) {
    if (isset($_POST['canva_link'])) {
    update_post_meta($order_id, '_canva_link', sanitize_text_field($_POST['canva_link']));
    }
    }

    What’s more strange is that when I am adding my shortcode to template instead of [canva_link] i see in a preview [object Object].

    Can you help me to solve this, lost few hours on it already.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.