0

I have a wordpress site where Iv assigned a global Variable $rushad and given it the value of a text box found on my product page.

global $rushad; 
if((isset($_POST['tmcp_textfield_0'])) && !empty($_POST['tmcp_textfield_1']))
{
    $rushad= $_POST['tmcp_textfield_0']; //note i used $_POST since you have a post form **method='post'**

}

I now want to use this information to trigger an email from a plugin Im using.

To do this I modified the plugins code like this....

function woocommerce_gift_coupon_send_action( $post_ids ) {
    global $wpdb;

    require_once WOOCOMMERCE_GIFT_COUPON_DIR . 'includes/mail-template.php';
    $generated_coupon = 0;
    foreach ( $post_ids as $post_id ) {
        $order                = new WC_Order( $post_id );
        $items                = $order->get_items();
        $mailto               = $rushad;
        $coupons_mail         = array();
        $sc                   = false;
        $coupons_to_generated = woocommerce_gift_coupon_check_order_coupons_count( $post_id );
        $coupons_generated    = woocommerce_gift_coupon_check_order_coupons( $post_id );

But its Not working yet.

Any Advice on where Im messing up?

  • What do you mean by "But its Not working yet."? – SaidbakR Apr 18 '18 at 18:50
  • @SaidbakR probably he expects to work by itself,I expect the same sometime too –  Apr 18 '18 at 18:52
  • If you're going to use globals (and this is definitely not a good idea), then they need to be imported into scope *everywhere* you're using them. Your `woocommerce_gift_coupon_send_action` function doesn't contain `global $rushad;`, so it doesn't know anything about it. Further reading: https://stackoverflow.com/questions/1557787/are-global-variables-in-php-considered-bad-practice-if-so-why – iainn Apr 18 '18 at 18:52
  • And if you add your code to the plugin where you want to use your variable? – Hugo Stiven Laguna Rueda Apr 18 '18 at 18:55
  • if I assign 'example@email.com' directly on the page and use it, it works. But I'm unable to get the users value from the Text Box to be used here. – user3596056 Apr 18 '18 at 18:57
  • @HugoStivenLaguna - No Luck with that either – user3596056 Apr 18 '18 at 18:58

1 Answers1

0

Variable $rushad will not work because it is not defined.

This will work like this global $rushad;

Tahir
  • 1
  • 1
  • Iv tried that too, The issue Im running into I think is, while $rushad= $_POST['tmcp_textfield_0']; works when I define it in functions.php...... It does not work when I try to define it directly in my plugins file. – user3596056 Apr 18 '18 at 19:24