Accepted date always show curent in WooCommerce when editing Order
-
Hi,
After installing the plugin, when I edit an Order on the Admin side in WooCommerce, for every order I see “GDPR accepted on: Accepted on 3rd May 2022 1:15 pm” – where the Accepted date is the current date when editing the Order and not the original date when the GDPR notice was accepted.I have commented out line [49] in /wp-gdpr-compliance/Integrations/Plugins/WooCommerce.php and added the folllwing to my child theme’s functions.php:
/* * Fix for GDPR Accepted on date */ /** * Gets text for (not) accepted consents * * @param string|bool $accepted * @return string */ function ziggle_getAcceptedDate( $date) { if ( empty( $date ) ) { return __( 'Not accepted.', 'wp-gdpr-compliance' ); } $date = Time::localDateFormat( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $date ); return sprintf( __( 'Accepted on %s.', 'wp-gdpr-compliance' ), $date ); } add_action( 'woocommerce_admin_order_data_after_order_details', 'ziggle_acceptedDateInOrderData' ); /** * @param \WC_Order $order */ function ziggle_acceptedDateInOrderData( \WC_Order $order ) { $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : ( property_exists( $order, 'ID' ) ? $order->get_id() : 0 ); $label = __( 'GDPR accepted on:', 'wp-gdpr-compliance' ); $date = get_post_meta( $order_id, '_wpgdprc', true ); $value = ziggle_getAcceptedDate( $date ); $text = sprintf( '<p class="form-field form-field-wide ziggle-wpgdprc-accepted-date"><strong>%1s</strong><br />%2s</p>', $label, $value ); echo apply_filters( 'wpgdprc_woocommerce_accepted_date_in_order_data', $text, $label, $value, $order ); }
When displaying a list of Orders, I have also added the following to my child theme’s functions.php
/** * Removes column with incorrect dates and add new column with correct dates * * @return array */ add_filter( 'manage_edit-shop_order_columns', 'ziggle_change_columns_filter',10,1); function ziggle_change_columns_filter( $columns ) { unset($columns['wpgdprc-privacy']); $columns[]='ziggle-wpgdprc-privacy'; return $columns; } add_action( 'manage_shop_order_posts_custom_column', 'ziggle_acceptedDateInOrderOverview' , 10, 2 ); /** * @param string $column * @param int $order_id * * @return string */ function ziggle_acceptedDateInOrderOverview( string $column = '', int $order_id = 0 ): string { if ( $column != 'ziggle-wpgdprc-privacy' ) { return $column; } $date = get_post_meta( $order_id, '_wpgdprc', true ); $value = ziggle_getAcceptedDate( $date ); echo apply_filters( 'wpgdprc_accepted_date_in_woocommerce_order_overview', $value, $order_id ); return $column; } add_filter( 'manage_edit-shop_order_columns', 'ziggle_acceptedDateColumnInOrderOverview' ); /** * @param array $columns * * @return array */ function ziggle_acceptedDateColumnInOrderOverview( array $columns = [] ): array { $text = apply_filters( 'wpgdprc_accepted_date_column_in_woocommerce_order_overview', 'Privacy policy'); $columns[ 'ziggle-wpgdprc-privacy' ] = $text; return $columns; }
These changes fix the problem.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Accepted date always show curent in WooCommerce when editing Order’ is closed to new replies.