sharingsunshine
asked on
Need PHP Message Posted In Woo Commerce Order Notes Box
This is a follow on from this question.
This is the current error
I need to make sure this message gets in the Order Notes section of the WooCommerce shopping cart.
I am running WooCommerce 4.9.8 and WooCommerce 3.5.4
It is important to get the message in order notes so it will be carried over to the backoffice. So, our personnel can act accordingly.
This is the current php code
https://www.experts-exchange.com/questions/29132557/Javascript-Button-Need-OnClick-To-Reset.html
This is the current error
<pre class="ee_debug" style="display: none">Array
(
[__stripe_mid] => 64c96aca-233e-4091-a8a5-2eef8b3ffc06
[wp-settings-69338] => editor=html
[wp-settings-time-69338] => 1548774822
[of_current_opt] => #of-option-globalsettings
[wp_woocommerce_session_ec34ebe84fc325c20ff14f13d4d89876] => ce0f477d8bf01c601d8f3113b3fcc354||1548969520||1548965920||2173822770d04d88ad3a9bfb8abc8cdb
[wordpress_test_cookie] => WP Cookie check
[woocommerce_items_in_cart] => 1
[woocommerce_cart_hash] => f1e39a061842b8f884c91f54c2ab6fba
[wordpress_logged_in_ec34ebe84fc325c20ff14f13d4d89876] => sharingsunshine|1548972461|sXqfvPjiY96SFwZJOXNyUKODb2YZtd8Vr1h6JHJkCrA|c4b2f47b2eead8b4f23032764afe3babd9932be9183650096fcd334a2d25e95d
[wantmembership] => 1
[__stripe_sid] => 43c996d1-f787-45db-b38e-74a122d96ec5
)
</pre>YES!<br />
<b>Fatal error</b>: Uncaught Error: Call to a member function add_order_note() on boolean in C:\xampp\htdocs\tfl\wp-content\themes\flatsome-child\functions.php:285
Stack trace:
#0 C:\xampp\htdocs\tfl\wp-includes\class-wp-hook.php(286): display_member(Object(WC_Checkout))
#1 C:\xampp\htdocs\tfl\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
#2 C:\xampp\htdocs\tfl\wp-includes\plugin.php(453): WP_Hook->do_action(Array)
#3 C:\xampp\htdocs\tfl\wp-content\plugins\woocommerce\templates\checkout\form-shipping.php(57): do_action('woocommerce_bef...', Object(WC_Checkout))
#4 C:\xampp\htdocs\tfl\wp-content\plugins\woocommerce\includes\wc-core-functions.php(211): include('C:\\xampp\\htdocs...')
#5 C:\xampp\htdocs\tfl\wp-content\plugins\woocommerce\includes\class-wc-checkout.php(269): wc_get_template('checkout/form-s...', Array)
#6 C:\xampp\htdocs\tfl\wp-includes\class-wp-hook.php(286): WC_Checkout->checkout_form_shipping('')
#7 C:\xampp\htdocs\tfl\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
# in <b>C:\xampp\htdocs\tfl\wp-content\themes\flatsome-child\functions.php</b> on line <b>285</b><br />
I need to make sure this message gets in the Order Notes section of the WooCommerce shopping cart.
I am running WooCommerce 4.9.8 and WooCommerce 3.5.4
It is important to get the message in order notes so it will be carried over to the backoffice. So, our personnel can act accordingly.
This is the current php code
add_action ('woocommerce_before_order_notes', 'display_member');
//echo '<pre class="ee_debug" style="display: none">' . print_r($_COOKIE, true) . '</pre>';
function display_member($order_id) {
echo '<pre class="ee_debug" style="display: none">' . print_r($_COOKIE, true) . '</pre>';
if (isset($_COOKIE['wantmembership'])) {
//if ($_COOKIE['wantmembership'] = 1) {
echo 'YES!';
//if (isset($_COOKIE['wantmembership:1'])) {
// The user wants membership
//echo "I want membership2";
$order = wc_get_order( $order_id );
// The text for the note
$note = __("I Want Membership");
// Add the note
$order->add_order_note( $note );
// Save the data
$order->save();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER