Dev Resources

  • Home
  • Reference
  • BuddyX Theme
  • Functions
  • Hooks
  • Classes
Filter by type:
Search
Browse: Home / Reference / Classes / WC_Email / WC_Email::save_template()

WC_Email::save_template( string $template_code, string $template_path )

Save the email templates.

Contents

  • Description
    • Parameters
    • Source
    • Changelog
  • Related
    • Uses
    • Used By
  • User Contributed Notes

Description #Description


Parameters #Parameters

$template_code

(Required) Template code.

$template_path

(Required) Template path.


Top ↑

Source #Source

File: includes/emails/class-wc-email.php

	protected function save_template( $template_code, $template_path ) {
		if ( current_user_can( 'edit_themes' ) && ! empty( $template_code ) && ! empty( $template_path ) ) {
			$saved = false;
			$file  = get_stylesheet_directory() . '/' . WC()->template_path() . $template_path;
			$code  = wp_unslash( $template_code );

			if ( is_writeable( $file ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writeable
				$f = fopen( $file, 'w+' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen

				if ( false !== $f ) {
					fwrite( $f, $code ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite
					fclose( $f ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
					$saved = true;
				}
			}

			if ( ! $saved ) {
				$redirect = add_query_arg( 'wc_error', rawurlencode( __( 'Could not write to template file.', 'woocommerce' ) ) );
				wp_safe_redirect( $redirect );
				exit;
			}
		}
	}

Expand full source code Collapse full source code


Top ↑

Changelog #Changelog

Changelog
Version Description
2.4.0 Introduced.

Top ↑

Related #Related

Top ↑

Uses #Uses

Uses
Uses Description
woocommerce.php: WC()

Returns the main instance of WC.

Top ↑

Used By #Used By

Used By
Used By Description
includes/emails/class-wc-email.php: WC_Email::process_admin_options()

Admin Panel Options Processing.


Top ↑

User Contributed Notes #User Contributed Notes

You must log in before being able to contribute a note or feedback.

Proudly powered by WordPress