coinbase / coinbase-commerce-woocommerce

Accept Bitcoin on your WooCommerce-powered website.
https://commerce.coinbase.com/integrate/woocommerce
Apache License 2.0
58 stars 40 forks source link

PHP Notice: payment_method was called **incorrectly**. Order properties should not be accessed directly. #16

Closed ciscospirit closed 5 years ago

ciscospirit commented 5 years ago

I found out that there is a PHP notice problem:

To fix this I checked into the coinbase-commerce.php and found there 2 references to "payment_method".

/**
 * Add order Coinbase meta after General and before Billing
 *
 * @see: https://rudrastyh.com/woocommerce/customize-order-details.html
 *
 * @param WC_Order $order WC order instance
 */
function cb_order_meta_general( $order )
{
    if ($order->payment_method == 'coinbase') {
        ?>

        <br class="clear"/>
        <h3>Coinbase Commerce Data</h3>
        <div class="">
            <p>Coinbase Commerce Reference # <?php echo esc_html($order->get_meta('_coinbase_charge_id')); ?></p>
        </div>

        <?php
    }
}
/**
 * Add Coinbase meta to WC emails
 *
 * @see https://docs.woocommerce.com/document/add-a-custom-field-in-an-order-to-the-emails/
 *
 * @param array    $fields indexed list of existing additional fields.
 * @param bool     $sent_to_admin If should sent to admin.
 * @param WC_Order $order WC order instance
 *
 */
function cb_custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    if ($order->payment_method == 'coinbase') {
        $fields['coinbase_commerce_reference'] = array(
            'label' => __( 'Coinbase Commerce Reference #' ),
            'value' => $order->get_meta( '_coinbase_charge_id' ),
        );
    }
    return $fields;
}

there i changed:

this: if ($order->payment_method == 'coinbase') { to: if ($order->get_payment_method() == 'coinbase') {

and

this:

function cb_custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    if ($order->payment_method == 'coinbase') {

to:

function cb_custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    if ($order->get_payment_method() == 'coinbase') {

This will fix the PHP notice problem.

ciscospirit commented 5 years ago

I have created a PR for this.