Mobile app version of vmapp.org
Login or Join
Shanna517

: Wordpress woocommerce php variable usage %1$s I am using wordpress with woocommerce and I am trying to manipulate a copy of myaccount.php The default code uses some variables of some sort that

@Shanna517

Posted in: #Php #Woocommerce #Wordpress

I am using wordpress with woocommerce and I am trying to manipulate a copy of myaccount.php The default code uses some variables of some sort that I am not familiar with nor have I been able to find documentation on. The variables in question are %1$s, %2$s and %s

<p class="myaccount_user">
<?php
printf(
__( 'Hello <strong>%1$s</strong> (not %1$s? <a href="%2$s">Sign out</a>).', 'woocommerce' ) . ' ',
$current_user->display_name,
wp_logout_url( get_permalink( wc_get_page_id( 'myaccount' ) ) )
);
?>

<?php
printf( __( 'From this page you can view your recent orders, manage your shipping and billing addresses and <a href="%s">edit your password and account details</a>.', 'woocommerce' ),
wc_customer_edit_account_url()
);
?>
</p>


How can I identify the variables, what they represent and how to use them?

Thank you.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Shanna517

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

The %1$s and %2$s are standard "conversion specifications" (ie. placeholders) used with the printf() family of PHP functions (nothing to do with WordPress or WooCommerce). They are replaced with the argument values that are passed to the printf() function.

So, in the first example, %1$s is replaced with the value of $current_user->display_name (1st argument) and %2$s is replaced with the value returned from wp_logout_url( get_permalink( wc_get_page_id( 'myaccount' ) ) ) (2nd argument).

The placeholder specifies how the value is displayed.


% indicates the start of the placeholder.
The number 1 that follows is a reference to which argument, either 1 or 2 in this example.
s indicates a string.


Further reference: php.net/manual/en/function.sprintf.php

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme