Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: shipping method title translate support #96

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions dokan-wpml.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ public function plugins_loaded() {
add_filter( 'dokan_set_store_categories', [ $this, 'set_translated_category' ] );
add_filter( 'dokan_get_store_categories_in_vendor', [ $this, 'get_translated_category' ] );

// shipping methods
add_action( 'dokan_shipping_method_title_update', [ $this, 'register_shipping_method_title' ] , 10, 3 );

add_filter( 'dokan_shipping_method_translatable_title', [ $this, 'get_translated_shipping_method_title' ], 10, 2 );

add_action( 'dokan_vendor_vacation_message_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
add_action( 'dokan_vendor_vacation_message_schedule_updated', [ $this, 'dokan_vendor_vacation_message_updated' ], 10, 3 );
add_filter( 'dokan_get_vendor_vacation_message', [ $this, 'get_translated_dokan_vendor_vacation_message' ], 10, 2 );
Expand Down Expand Up @@ -1400,6 +1405,35 @@ public function register_vendor_verification_method( int $method_id ) {
$this->register_single_string( 'dokan', 'Dokan Vendor Verification Method Help Text: ' . $method->get_help_text(), $method->get_help_text() );
}

/**
* Register shipping method title for string translation.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return void
*/

public function register_shipping_method_title( $title,$instance_id ){
$this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
}

/**
* Get translated shipping method title.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return string
*/

public function get_translated_shipping_method_title ( $title,$instance_id ): string {
return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
}
Comment on lines +1408 to +1436
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve method consistency and type safety.

The new methods need improvements for better consistency and type safety:

Apply these changes:

-    public function register_shipping_method_title( $title,$instance_id ){
+    public function register_shipping_method_title( string $title, int $instance_id ): void {
         $this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
     }

-    public function get_translated_shipping_method_title ( $title,$instance_id ): string {
+    public function get_translated_shipping_method_title( string $title, int $instance_id ): string {
         return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
     }

Changes:

  1. Added parameter type hints for better type safety
  2. Added void return type to register_shipping_method_title()
  3. Fixed spacing in method parameters
  4. Fixed spacing in method name
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Register shipping method title for string translation.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return void
*/
public function register_shipping_method_title( $title,$instance_id ){
$this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
}
/**
* Get translated shipping method title.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return string
*/
public function get_translated_shipping_method_title ( $title,$instance_id ): string {
return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
}
/**
* Register shipping method title for string translation.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return void
*/
public function register_shipping_method_title( string $title, int $instance_id ): void {
$this->register_single_string( 'dokan', 'Dokan Shipping Method Title: ' . $instance_id, $title );
}
/**
* Get translated shipping method title.
*
* @since 1.1.6
*
* @param string $title Shipping Method Title.
* @param int $instance_id Shipping Method Instance ID.
*
* @return string
*/
public function get_translated_shipping_method_title( string $title, int $instance_id ): string {
return $this->get_translated_single_string( $title, 'dokan', 'Dokan Shipping Method Title: ' . $instance_id );
}

Comment on lines +1418 to +1436
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix phpcs issues and add type casting.

/**
* Get translated Verification Method Title.
*
Expand Down